/*
TASK:hop
LANG:C++
*/
#include <stdio.h>
#include <set>
#include <queue>
#define FOR(i,n) for(int i=0;i<n;i++)

typedef long long lld;
typedef std::set<lld> mySet;

struct type {
       lld code;
       int way;
       type() {}
       type(lld _code,int _way) {
                code = _code;
                way = _way;
       }
};

int dx[5] = { 0,0,0,1,-1 };
int dy[5] = { 0,1,-1,0,0 };

std::queue<type> q;
std::set<lld> s;
int x1,y1,x2,y2;
int n,m;
int s1,s2;

void init() {
     scanf("%d %d",&n,&m);
     scanf("%d %d %d",&x1,&y1,&s1);
     scanf("%d %d %d",&x2,&y2,&s2);
}

lld encode(int x1,int y1,int x2,int y2) {
    lld res(0);
    res = x1;
    res *= (m+1);
    res += y1;
    res *= (n+1);
    res += x2;
    res *= (m+1);
    res += y2;
    return res;
}
void decode(lld res,int &x1,int &y1,int &x2,int &y2) {
     y2 = res % (m+1);
     res /= (m+1);
     x2 = res % (n+1);
     res /= (n+1);
     y1 = res % (m+1);
     res /= (m+1);
     x1 = res % (n+1);
}
bool over(int xa,int ya,int xb,int yb) {
     return (xa==xb && ya==yb);
}
bool isIn(int xa,int ya) {
     return (xa>=0 && xa<=n && ya>=0 && ya <= m);
}
void bfs() {
     lld start = encode( x1, y1, x2, y2 );
     q.push(type(start, 0) );
     s.insert(start);
     while(!q.empty()) {
                 type f = q.front();
                 q.pop();
                 int xa,ya,xb,yb;
                 decode(f.code, xa, ya, xb, yb);
                 FOR(i,5) {
                    FOR(j,5) {
                       if(i==0 && j==0) continue;
                       int nxa,nxb,nya,nyb;
                       nxa = dx[i] * s1 + xa;
                       nxb = dx[j] * s2 + xb;
                       nya = dy[i] * s1 + ya;
                       nyb = dy[j] * s2 + yb;
                       if(isIn(nxa,nya) && isIn(nxb,nyb)) {
                          if(over(nxa,nya,nxb,nyb)) {
                            printf("%d\n", f.way+1);
                            return;
                          }
                          lld next = encode(nxa,nya,nxb,nyb);
                          if(s.find(next) == s.end()) {
                             s.insert(next);
                             q.push( type(next, f.way + 1) );
                          }
                       }
                    }
                 }
     }
     printf("0\n");
}

int main() {
    init();
    bfs();
    return 0;
}
