dx,dy = map(int, input().split())
ax,ay = map(int, input().split())
bx,by = map(int, input().split())

x1=abs(ax-bx)
x2=ax+dx-bx
x3=dx-ax+bx

x=min(x1,x2,x3)

y1=abs(ay-by)
y2=ay+dy-by
y3=dy-ay+by

y=min(y1,y2,y3)

print(x+y)