t = 1 #t = int(input()) def f(s,g): if s > g: return g+n-s return g-s for _ in range(t): n,q,s,t,c = map(int, input().split()) s -= 1 t -= 1 for i in range(q): u,v = map(int, input().split()) u -= 1 v -= 1 ans = f(u,v) a1 = f(u,s) + c + f(t,v) print(min(ans,a1))