N,M,K,S,T = map(int,input().split()) roka = [] from_list = [[S,0]] to_list = [] ans = -1 def calc(from_list,to_list): next_list = [] for to in to_list: tmp_n = [to[1],float("inf")] for frm in from_list: step = abs(to[0]-frm[0])+frm[1] if tmp_n[1]>step: tmp_n[1]=step next_list.append(tmp_n[:]) return next_list[:] for i in range(M): roka.append(list(map(int,input().split()))) roka.sort() now_buil = 1 for rk in roka: if rk[0]==now_buil: to_list.append(rk[1:]) else: now_buil+=1 if rk[0]>now_buil: break else: from_list = calc(from_list,to_list) to_list = [rk[1:]] else: if now_buil+1 == N and M != 0: from_list = calc(from_list,to_list) ans = float("inf") for frm in from_list: step = abs(T-frm[0])+frm[1] if ans>step: ans=step print(ans)