// 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=898251#1

#include<iostream>
#include<cstdlib>
using namespace std;
#define WIDTH 4
#define HEIGHT 2
#define MAX WIDTH * HEIGHT
#define LIMIT 50

struct Puzzle{
    char cont[MAX];
    int space; 
};

Puzzle puzzle;
int limit,path[LIMIT],MD[MAX][MAX];

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

int getHeuristic(){
  int sum = 0;
  for(int i = 0;i < MAX;++i){
    if(puzzle.cont[i]=='0')continue;
    sum += MD[i][puzzle.cont[i] - '0'];
  }
  return sum;
}

bool isSolved(){
  for(int i = 0;i < MAX;++i){
    if(puzzle.cont[i] != '0' + i )return false;
  }
  return true;
}

bool dfs(int depth,int prev){
  if(isSolved())return true;
  
  if(depth + getHeuristic() > limit) return false;

  int px,py,tx,ty;
  Puzzle tmp;
  px = puzzle.space % 4;
  py = puzzle.space / 4;
  
  for(int r = 0;r < 4;++r){
    tx = px + dx[r];
    ty = py + dy[r];

    if(max(prev,r) - min(prev,r) == 2)continue;
    if(tx < 0 || ty < 0 || tx >= WIDTH || ty >= HEIGHT)continue;

    tmp = puzzle;
    puzzle.cont[py * WIDTH + px] = puzzle.cont[ty * WIDTH + tx];
    puzzle.cont[ty * WIDTH + tx] = '0';
    puzzle.space = (ty * WIDTH) + tx;

    if(dfs(depth + 1,r)){
        path[depth] = r;
        return true;
    }
    puzzle = tmp;
  }
  return false;
}

void solve(){
  for(limit = getHeuristic();limit <= LIMIT;limit += 2){
    if(dfs(0,-100)){
      cout << limit << endl;
      return;
    }
  }
  cout << "unsolvable" << endl;
}

int main(){
    for(int i = 0;i < MAX;++i){
        for(int j = 0;j < MAX;++j){
            MD[i][j] = abs((i / 4) - (j / 4)) + abs((i % 4) - (j % 4));
        }
    }
    while(1){
        try{
            for(int i = 0;i < MAX;++i){
                cin >> puzzle.cont[i];
                if(cin.fail()){
                    throw "end";
                }
                if(puzzle.cont[i] == '0'){
                    puzzle.space = i;
                }
            }
            solve();
        } catch (const char* e) {
            break;
        }
    }
}
