n, m, xs, ys, xt, yt =map(int,input().split())
a, b =[],[]for i inrange(n):
a.append(list(map(int,input().split())))for i inrange(n):
b.append(list(map(int,input().split())))# 准备工作
xt, yt = xt-1, yt-1import heapq
pq =[(0, xs-1, ys-1)]
mat =[[-1]*m for i inrange(n)]# 用于计算对于当前时间当前十字路口那个方向可以通行,# 同时返回去另一个方向需要等待的时间defrule(t, i, j):
ax, bx = a[i][j], b[i][j]
t = t %(ax + bx)if t < ax:returnTrue, ax - t
else:returnFalse, ax + bx - t
while pq:
min_t, i, j = heapq.heappop(pq)if mat[i][j]!=-1:continue
mat[i][j]= min_t
if i == xt and j == yt:
ans = min_t
break
direc, t_w = rule(min_t, i, j)for step in[1,-1]:
ni, nj = i + step, j + step
if0<= nj < m:
heapq.heappush(pq,(min_t +1+(t_w if direc else0), i, nj))if0<= ni < n:
heapq.heappush(pq,(min_t +1+(0if direc else t_w), ni, j))print(ans)