n,m = map(int,input().split()) ms = [list(map(int,input().split())) for i in range(m)] ms.sort(reverse = True) now = n ans = 0 for s,t in ms: if now >= t: ans += (now - t)*2 now = s ans += t*2 - s*2 - 1 ans+=(now-1)*2 print(ans)