import sys input = sys.stdin.readline def linput(tt=int): return list(map(tt,input().split())) def main(): H,W = linput() sr,sc = linput() gr,gc = linput() res = abs(gc-sc) + abs(gr-sr) print(res) if __name__ == "__main__": main()