local w, h = io.read("*n", "*n", "*l") local str = "" local col = {} local done = {} for i = 1, h do str = io.read() local idx = (i - 1) * w for v in str:gmatch("%d+") do idx = idx + 1 col[idx] = tonumber(v) done[idx] = false end end local function search(startpos) local tasks = {startpos} local tasknum, donenum = 1, 0 while donenum < tasknum do donenum = donenum + 1 local idx = tasks[donenum] done[idx] = true local known = 0 if w ~= 1 then if idx % w ~= 0 and col[idx + 1] == col[idx] then if done[idx + 1] then known = known + 1 else table.insert(tasks, idx + 1) tasknum = tasknum + 1 end end if idx % w ~= 1 and col[idx - 1] == col[idx] then if done[idx - 1] then known = known + 1 else table.insert(tasks, idx - 1) tasknum =tasknum + 1 end end end if h ~= 1 then if idx <= (h - 1) * w and col[idx + w] == col[idx] then if done[idx + w] then known = known + 1 else table.insert(tasks, idx + w) tasknum = tasknum + 1 end end if w < idx and col[idx - w] == col[idx] then if done[idx - w] then known = known + 1 else table.insert(tasks, idx - w) tasknum =tasknum + 1 end end end if 2 <= known then return true end end return false end local curpos = 1 local found = false while curpos <= h * w do found = search(curpos) if found then break end curpos = curpos + 1 while curpos <= h * w and done[curpos] do curpos = curpos + 1 end end print(found and "possible" or "impossible")