#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


const int N = 4;
const int NN = N * N;
const int LIMIT = 100;
int MDT[NN][NN];

struct Puzzle{
    int num[NN], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
char dir[4] = {'r', 'u', 'l', 'd'};

int getAllMD(Puzzle &pz){
    int sum = 0;
    for(int i = 0; i < NN; ++i){
        if(pz.num[i] == NN) continue;
        sum += MDT[i][pz.num[i] - 1];
    }
    return sum;
}

bool isGoal(){
    REP(i, NN)
        if(state.num[i] != i+1) return false;
    return true;
}

bool dfs(int depth, int prv){
    if(state.MD == 0) return true;
    if(depth + state.MD > limit) return false;

    int sx = state.space / N;
    int sy = state.space % N;

    REP(r, 4){
        int nx = sx + dx[r];
        int ny = sy + dy[r];
        if(nx<0 || ny<0 || nx>=N || ny>=N) continue;
        if(max(prv, r) - min(prv, r) == 2) continue;
        Puzzle tmp = state;
        state.MD -= MDT[nx*N + ny][state.num[nx*N + ny] - 1];
        state.MD += MDT[sx*N + sy][state.num[nx*N + ny] - 1];
        swap(state.num[nx*N + ny], state.num[sx*N + sy]);
        state.space = nx*N + ny;
        if(dfs(depth+1, r)){
            path[depth] = r; return true;
        }
        state = tmp;
    }
    return false;
}

string iterativeDeeping(Puzzle &in){
    in.MD = getAllMD(in);
    for(limit = in.MD; limit <= LIMIT; ++limit){
        state = in;
        if(dfs(0, -100)){
            string ans = "";
            REP(i, limit) ans += dir[path[i]];
            return ans;
        }
    }
    return "";
}

int main(){
    for(int i = 0; i < NN; ++i){
        for(int j = 0; j < NN; ++j)
            MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
    }
    Puzzle in;
    REP(i, NN){
        cin >> in.num[i];
        if(in.num[i] == 0){
            in.num[i] = NN;
            in.space = i;
        }
    }
    string ans = iterativeDeeping(in);
    cout << ans.length() << endl;
    return 0;
}



Measured memory_bytes: 3212