### BUGGY CODE ###

from heapq import heapify, heappush, heappop
from copy import deepcopy, copy
dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)
dir = ('r', 'u', 'l', 'd')
N = 4
N2 = 16
LIMIT = 46
MDT = tuple(tuple(abs(i // N - j // N) + abs(i % N - j % N) for j in range(N2)) for i in range(N2))
class Puzzle:
    def __init__(self):
        self.f = []
        self.space, self.MD = 0, 0
state = Puzzle()
path = [0] * LIMIT
def getAllMD(pz):
    global MDT
    sum_mdt = 0
    for i in range(N2):
        if pz.f[i] == N2:
            continue
        sum_mdt += MDT[i][pz.f[i] - 1]
    return sum_mdt
def dfs(depth, prev, limit, state, path):
    if state.MD == 0:
        return True
    if depth + state.MD > limit:
        return False
    sx = state.space // N
    sy = state.space % N
    for r in range(4):
        tx = sx + dx[r]
        ty = sy + dy[r]
        if tx < 0 or tx >= N or ty < 0 or ty >= N:
            continue
        if max(prev, r) - min(prev, r) == 2:
            continue
        tmp = deepcopy(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]
        state.f[tx * N + ty], state.f[sx * N + sy] = state.f[sx * N + sy], state.f[tx * N + ty]
        state.space = tx * N + ty
        if dfs(depth + 1, r, limit, state, path):
            return True
        state = deepcopy(tmp)
    return False
def iterative_deepening(pin, state, path):
    pin.MD = getAllMD(pin)
    ans = ""
    for limit in range(pin.MD, LIMIT + 1):
        state = deepcopy(pin)
        if dfs(0, -100, limit, state, path):
            return limit
    return "unsolvable"
in0 = Puzzle()
in0.f = sum([list(map(int, input().split())) for _ in range(N)], [])
t = in0.f.index(0)
in0.f[t] = N2
in0.space = t
print(iterative_deepening(in0, state, path))



### FIXED CODE ###

from heapq import heappop, heappush
manhattan = tuple(tuple(abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)) for i in range(16))
movables = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11),
            (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14))
swap_mul = tuple(tuple((1 << mf) - (1 << mt) for mt in range(0, 64, 4)) for mf in range(0, 64, 4))
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, input().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
    estimation, board, blank = heappop(queue)
    if board in visited:
        continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited:
            continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45:
            continue
        heappush(queue, (new_estimation, new_board, new_blank))