n=input()
n=n.split(" ")
a=[]
x=[]
y=0
m=0
c=0
for i in range(int(n[0])):
    b=input()
    a.append(b)
for i in a:
    for j in i:
        if j=="0":
            x.append([i.index(j),a.index(i)])
        else:
            y+=1
for i in x:
    m+=i[1]-c
    c=i[1]
print(m)
