### constant

MAX_INT = 1 << 30

DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### subroutines

def gen_dice
  dice = {}
  st = 123
  used = {}
  used[st] = true
  q = [st]

  while ! q.empty?
    u = q.shift

    u0 = u / 100
    u1 = (u / 10) % 10
    u2 = u % 10

    dice[u] = [
      (7 - u2) * 100 + u1 * 10 + u0,
      u1 * 100 + (7 - u0) * 10 + u2,
      u2 * 100 + u1 * 10 + (7 - u0),
      (7 - u1) * 100 + u0 * 10 + u2
    ]

    for v in dice[u]
      if ! used[v]
        used[v] = true
        q << v
      end
    end
  end

  dice
end

### main

dice = gen_dice
#p dice

loop do
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0

  mtx = h.times.map{gets.split.map(&:to_i)}
  sy, sx = gets.split.map(&:to_i)
  gy, gx = gets.split.map(&:to_i)
  #p mtx
  #p [sx, sy]
  #p [gx, gy]

  sid = sy * w + sx
  gid = gy * w + gx

  dists = Hash.new{MAX_INT}
  min_dist = MAX_INT

  st = sid * 1000 + 123
  dists[st] = 0
  q = [st]

  while ! q.empty?
    u = q.min{|a, b| dists[a] <=> dists[b]}
    q.delete(u)

    du = dists[u]

    udc = u % 1000
    uid = u / 1000
    uy = uid / w
    ux = uid % w
    #p [udc, ux, uy, du]

    if uid == gid
      min_dist = du if min_dist > du
      next
    end

    for i in (0..3)
      vx = ux + DXYS[i][0]
      vy = uy + DXYS[i][1]

      if vx >= 0 && vx < w && vy >= 0 && vy < h
        vdc = dice[udc][i]
        vid = vy * w + vx
        v = vid * 1000 + vdc

        dv = dists[v]
        ndv = du + (7 - vdc / 100) * mtx[vy][vx]

        if dv > ndv
          dists[v] = ndv
          if dv >= MAX_INT
            q << v
          end
        end
      end
    end
  end

  puts min_dist
end