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;
        const int LIMIT = 45;
        static int limit;
        static int[] path = new int[LIMIT];
        static int[,] MDT = new int[N2, N2];
        static int[] dx = { 0, -1, 0, 1 };
        static int[] dy = { 1, 0, -1, 0 };
        static char[] dir = { 'r', 'u', 'l', 'd' };
        static Puzzle state;


        static bool checker()
        {
            for (int i = 0; i < N2; i++)
            {
                if (state.f[i] != i + 1) return false;
            }
            return true;
        }
        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)
            {
                //Console.WriteLine(string.Join(" ",state.f));
                return true;
            }
            if (depth + state.MD > limit) return false;

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


            for (int r = 0; r < 4; r++)
            {
                //Console.WriteLine(state.MD +" "+state.space +"  " + string.Join(" ", state.f));
                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;

                var tmp = new Puzzle();
                P_COPY(tmp, state);
                state.MD -= MDT[tx * N + ty, state.f[tx * N + ty] - 1];
                state.MD += MDT[sx * N + sy, state.f[tx * N + ty] - 1];

                SWAP(state.f, tx * N + ty, sx * N + sy);
                state.space = tx * N + ty;
                if (DFS(depth + 1, r))
                {
                    path[depth] = r;
                    return true;
                }

                state = new Puzzle();
                P_COPY(state, tmp);
            }
            return false;
        }
        static void SWAP(int[] a, int x, int y)
        {
            var t = a[x];
            a[x] = a[y];
            a[y] = t;
        }
        static int GetAllMD(Puzzle P)
        {
            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 string IDA(Puzzle P)
        {
            P.MD = GetAllMD(P);
           // Console.WriteLine(string.Concat(P.f) + P.space + P.MD);

            for (limit = P.MD; limit <= LIMIT ; limit++)
            {
                state = new Puzzle();
                P_COPY(state, P);
                if(DFS(0, -45))
                {
                    var ans = "";
                    for (int i = 0; i < limit; i++)
                    {
                        ans += dir[path[i]];
                    }
                    return ans;
                }
            }

            return "unsolvable"; 
        }
        static void Main(string[] args)
        {
            var P = new Puzzle();

            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++)
                {
                    P.f[N * i + j] = t[j];
                    if (t[j] == 0)
                    {
                        P.f[N * i + j] = N2;
                        P.space = N * i + j;
                    }
                }
                
            }
            string ans = IDA(P);
            //Console.WriteLine(ans);
            Console.WriteLine(ans.Length);
        }
      

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 9224