using System;

namespace ALDS1_13_C
{
    class Puzzle
    {
        internal int[] f;
        internal int space, MD;
        public Puzzle()
        {
            f = new int[16];
            space = 0;
            MD = 0;
        }
    }
    class Program
    {
        const int N = 4;
        const int N2 = 16;
        static int LIMIT = 45;
        static int limit;
        static int[,] MDT = new int[N2, N2];
        static int[] dx = { 0, -1, 0, 1 };
        static int[] dy = { 1, 0, -1, 0 };
        static Puzzle state = new Puzzle();
        static Puzzle P = new Puzzle();

        static void P_COPY(Puzzle x, Puzzle y)
        {
            x.f = (int[])y.f.Clone();
            x.space = y.space;
            x.MD = y.MD;
        }
        static bool DFS(int depth, int prev)
        {
            if (state.MD == 0) return true;
            if (depth + state.MD > limit) return false;

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

            var tmp = new Puzzle();
            for (int r = 0; r < 4; r++)
            {
                int tx = sx + dx[r];
                int ty = sy + dy[r];
                if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
                if (Math.Abs(prev - r) == 2) continue;

                P_COPY(tmp, state);

                int T = tx * N + ty;
                int S = sx * N + sy;
                state.MD -= MDT[T, state.f[T] - 1];
                state.MD += MDT[S, state.f[T] - 1];

                int tt = state.f[T];
                state.f[T] = state.f[S];
                state.f[S] = tt;

                state.space = T;

                if (DFS(depth + 1, r)) return true;
  
                P_COPY(state, tmp);
            }
            return false;
        }
   
        static int GetAllMD()
        {
            int sum = 0;
            for (int i = 0; i < N2; i++)
            {
                if (P.f[i] == N2) continue;
                sum += MDT[i, P.f[i] - 1];
            }
            return sum;
        }
        static void IDA()
        {
            P.MD = GetAllMD();
            for (limit = P.MD; limit <= LIMIT ; limit++)
            {
                P_COPY(state, P);
                if(DFS(0, -45))
                {
                    Console.WriteLine(limit);
                    return;
                }
            }
        }
        static void Main(string[] args)
        {
            for (int i = 0; i < N2; i++)
            {
                for (int j = 0; j < N2; j++)
                {
                    MDT[i, j] = Math.Abs(i / N - j / N) + Math.Abs(i % N - j % N);
                }
            }       
            for (int i = 0; i < N; i++)
            {
                var t = scan;
                for (int j = 0; j < N; j++)
                {
                    var p = N * i + j;
                    P.f[p] = t[j];
                    if (t[j] == 0)
                    {
                        P.f[p] = N2;
                        P.space = p;
                    }
                }               
            }
            IDA();
        }
      
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 9296