from autoimp import *

try: where = int(sys.argv[1])
except IndexError:
    where = 1

def pathname(i):
    return 'chapters/Chapter'+str(i)+'.md'

for total in itertools.count(0):
    if not os.path.exists(pathname(total+1)): break

for i in range(total,where-1,-1):
    print(pathname(i),pathname(i+1))
    os.rename(pathname(i),pathname(i+1))

os.execlp('emacs','emacs',pathname(where))
        
