#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
short d[22][22][11] ={};
int ans = 100;

void dfs(i_i p, int t) {
    if(t > 10) return;
    rep(i,4){
        i_i m = p;
        if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) continue; 
        while(1) {
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 0) break;
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 4) {
                ans = min(ans,t); 
                break;
            }
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) {
                rep(j,22) {
                    rep(k,22) {
                        d[j][k][t+1] = d[j][k][t];
                    }
                }
                d[m.first+dx[i]][m.second+dy[i]][t+1] = 1;
                dfs(make_pair(m.first,m.second),t+1); 
                break;
            } else {
                m.first += dx[i], m.second += dy[i];
            }
        }
    }
}

int main() {
    while(1) {
        int w,h;
        i_i s;
        ans = 100;
        memset(d,0,sizeof(d)); 
        cin >> w >> h;
        if(w==0) break;
        FOR(j,1,h+1) {
            FOR(i,1,w+1) {
                cin >> d[i][j][1];
                if(d[i][j][1] == 2){s = make_pair(i,j); d[i][j][1] = 0; }
                d[i][j][1] += 1;
            }
        }
        dfs(s,1);
        ans == 100? cout << -1 << endl:cout << ans << endl;
    }
    return 0;
    }
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int main() {
  int A , B;
  cin >> A >> B;

  int MAX = max(A, B), MIN = min(A, B);
  if (MAX == 1) {
    cout << "1 2\n.#" << BR;
    return 0;
  }
  string S = ".#";
  if (MAX == A) S = "#.";

  int H = 90, W = 80;
  vector<vector<ll>> cells(H, vector<ll>(W , 0));

  int h = 1, w = 1;
  while(MAX > 1) {
    cells[h][w] = 1;
    if (w + 2 < W) {
      w += 2;
    } else {
      h += 3;
      w = 1;
    }
    MAX--;
  }

  if (MIN > 1) rep(i, h + 2, H) rep0(j, W) cells[i][j] = 1;
  else cells[H - 1][W - 1] = 1;

  h += 3;
  w = 1;
  MIN--;
  while(MIN > 0) {
    cells[h][w] = 0;
    if (w + 2 < W) {
      w += 2;
    } else {
      h += 3;
      w = 1;
    }
    MIN--;
  }

  cout << H << SP << W << BR;
  rep0(i, H) {
    rep0(j, W) {
      cout << S[cells[i][j]];
    }
    cout << BR;
  }

  return 0;
}