### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(1000000)

def yn(b):
    print("Yes" if b==1 else "No")
    return
def aaa(g,memo,www,c):
    ww = www[g]
    memo[g]=c
    c2 = (c+1)
    for i in range(len(ww)):
        w=ww[i]
        if w==1 and i!=g:
            if memo[i]==-1 or memo[i] > c2:
                aaa(i,memo,www,c2)

def tansaku(y,x,mp,done,grp,wrp,w,h,gm,xxx):
    wlkh=[y,y,y-1,y+1]
    wlkw=[x-1,x+1,x,x]
    nun=y*w+x
    grp.add(nun)
    gm[nun]=xxx
    for zzz in range(4):
        zh=wlkh[zzz]
        zw=wlkw[zzz]
        if zh < 0:
            continue
        if zh >= h:
            continue
        if zw < 0:
            continue
        if zw >= w:
            continue
        if mp[zh][zw] == "." and done[zh][zw]==0:
            done[zh][zw]=1
            tansaku(zh,zw,mp,done,grp,wrp,w,h,gm,xxx)
    for i in range(y-2,y+3):
        for j in range(x-2,x+3):
            if i < 0:
                continue
            if i >= h:
                continue
            if j < 0:
                continue
            if j >= w:
                continue
            if mp[i][j]==".":
                wrp.add(i*w+j)

def resolve():
    readline=sys.stdin.readline

    h,w=map(int, readline().rstrip().split())
    ch,cw=map(int, readline().rstrip().split())
    dh,dw=map(int, readline().rstrip().split())
    ch-=1
    cw-=1
    dh-=1
    dw-=1
    mp=[]

    cN=ch*w+cw
    dN=dh*w+dw

    done=[[0 for i in range(w)] for j in range(h)]
    gm=[-1] * ((h*w)+3)

    road=0
    for i in range(h):
        ss=readline().rstrip()
        road+=ss.count(".")
        mp.append(ss)

    gs = []
    ws=[]
    xxx=-1
    for y in range(h):
        for x in range(w):
            masu=y*w+x
            if mp[y][x] == "." and done[y][x]==0:
                grp=set()
                wrp=set()
                xxx+=1
                tansaku(y,x,mp,done,grp,wrp,w,h,gm,xxx)
                gs.append(grp)
                ws.append(wrp)
            else:
                done[y][x]=1
    cnt=len(gs)
    www=[[0 for i in range(cnt)] for j in range(cnt)]
    for i in range(cnt):
        gp = gs[i]
        wp = ws[i]
        for pp in wp:
            j=gm[pp]
            www[i][j]=1
            www[j][i]=1
    memo=[-1]*cnt
    #aaa(gm[cN],memo,www,0)
    print(memo[gm[dN]])
    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


### FIXED CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,x,k=map(int, readline().rstrip().split())
    s=n//x
    if n%x > 0:
        s+=1
    print(s*k)
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------