#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

#define EMP 0
#define OBS 1
#define WAL 4
#define STT 2
#define GOA 3

#define SUPmaxY 22
#define SUPmaxX 22

int maxY,maxX;
int field[SUPmaxX][SUPmaxY];
int startX,startY;
int result;


int dfs(int x, int y, int depth){
	//DEBUG(x);DEBUG(y);DEBUG(depth);
	if(depth>=result) return 0;
	if(field[x][y]==GOA) {result=depth; return 0;}
	
	FOR(di,0,4){
		int nx=x; int ny=y;
		int dx=DX[di]; int dy=DY[di];
		if(field[x+dx][y+dy]==OBS) continue;
		while(field[nx][ny]==EMP){
			nx+=dx;ny+=dy;
		}
		if(field[nx][ny]==WAL){continue;}
		if(field[nx][ny]==GOA){result=depth+1; return 0;}
		if(field[nx][ny]==OBS){
			field[nx][ny]=EMP;
			dfs(nx-dx,ny-dy,depth+1);
			field[nx][ny]=OBS;
		}
	}
	

}



int main(){
	while(true){
		cin>>maxY>>maxX;			if(!maxY) return 0;
		maxX+=2;maxY+=2;
		FOR(x,0,maxX) FOR(y,0,maxY) field[x][y]=WAL;
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) cin>>field[x][y];
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) if(field[x][y]==STT){startX=x;startY=y;field[x][y]=EMP;}

		result=11;
		dfs(startX,startY,0);
		cout<< ((result==11)?-1:result) <<endl;
	}
}
#include <iostream>
#include <vector>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;

const int dx[5] = { 0, 0, 0, 1, -1 };
const int dy[5] = { 0, 1, -1, 0, 0 };

int w, h;
int sx, sy, gx, gy;
VVI M;
int answer;

//==================================================
// Tõ
//==================================================
void dfs( int x, int y, int a, int d )
{
	if ( d > 10 ) return;

	if ( M[y][x] == 3 )
	{
		if ( answer == -1 )
			answer = d;
		else
			answer = min( answer, d );
	}
	if ( a > 0 )
	{
		int nx = x + dx[a];
		int ny = y + dy[a];
		if ( nx < 0 || nx >= w || ny < 0 || ny >= h )
			return;
		if ( M[ny][nx] == 1 )
		{
			M[ny][nx] = 0;
			dfs( x, y, 0, d );
			M[ny][nx] = 1;
		}
		else
			dfs( nx, ny, a, d );
	}
	else
	{
		for ( int i = 1; i < 5; i++ )
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if ( nx < 0 || nx >= w || ny < 0 || ny >= h )
				continue;
			if ( M[ny][nx] == 0 || M[ny][nx] == 3 )
			{
				dfs( nx, ny, i, d+1 );
			}
		}
	}

}

int main( void )
{
	while ( cin >> w >> h && w && h )
	{
		//==================================================
		// Ï
		//==================================================
		M = VVI( h, VI( w, 0 ) );
		answer = -1;

		//==================================================
		// }bvÌüÍ
		//==================================================
		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				int& s = M[i][j];
				cin >> s;

				// X^[gES[
				if ( s == 2 )
				{
					sx = j;
					sy = i;
					s  = 0;
				}
				else if ( s == 3 )
				{
					gx = j;
					gy = i;
				}
			}
		}

		//==================================================
		// 
		//==================================================
		dfs( sx, sy, 0, 0 );

		//==================================================
		// oÍ
		//==================================================
		cout << answer << endl;
	}
	return 0;
}