const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const arr = (await readline()).split(",").map(Number);
const n = Math.sqrt(arr.length, 2);
const matrix = [];
for (let i = 0; i < n; i++) {
matrix.push(arr.slice(i * n, (i + 1) * n));
}
const queue = [];
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (matrix[i][j] === 1) {
queue.push([i, j]);
}
}
}
const offsets = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
];
let healthy = arr.length - queue.length;
let time = 0;
while (queue.length) {
let size = queue.length;
for (let i = 0; i < size; i++) {
const [x, y] = queue.shift();
for (let [offsetX, offsetY] of offsets) {
const newX = x + offsetX;
const newY = y + offsetY;
if (
newX >= 0 &&
newX < n &&
newY >= 0 &&
newY < n &&
matrix[newX][newY] === 0
) {
matrix[newX][newY] = 1;
queue.push([newX, newY]);
healthy--;
}
}
}
time++;
if (healthy === 0) break;
}
console.log(time);
})();