#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int a[6][6], ans, idx, idy;
for(int i=0; i<5; i++) for(int j=0; j<5; j++) {scanf("%d", &a[i][j]); if(a[i][j]) idx=i, idy=j;}
ans=abs(idx-2)+abs(idy-2);
printf("%d", ans);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBhWzZdWzZdLCBhbnMsIGlkeCwgaWR5OwoJZm9yKGludCBpPTA7IGk8NTsgaSsrKSBmb3IoaW50IGo9MDsgajw1OyBqKyspIHtzY2FuZigiJWQiLCAmYVtpXVtqXSk7IGlmKGFbaV1bal0pIGlkeD1pLCBpZHk9ajt9CglhbnM9YWJzKGlkeC0yKSthYnMoaWR5LTIpOwoJcHJpbnRmKCIlZCIsIGFucyk7CglyZXR1cm4gMDsKfQ==