require 'set'

Move = [ [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]
        ]

R = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
C = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]

Factorials = (1...16).each_with_object([1]){ |i, arr| arr << arr[-1] * i }.reverse

def min_heapify(x = 1)
  l = 2*x
  r = 2*x+1
  if l <= $n && $heap[l][0] < $heap[x][0]
    minimum = l
  else
    minimum = x
  end
  if r <= $n && $heap[r][0] < $heap[minimum][0]
    minimum = r
  end
  if minimum != x
    $heap[x], $heap[minimum] = $heap[minimum], $heap[x]
    min_heapify(minimum)
  end
end

def extract
  key = $heap[1]
  $heap[1] = $heap[$n]
  $n -= 1
  min_heapify
  key
end

def insert(key)
  $n += 1
  $heap[$n] = key
  i = $n
  while i > 1 && $heap[i/2][0] > $heap[i][0]
    $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
    i /= 2
  end
end

def create_hash(brd)
  b = brd.dup
  16.times do |i|
    (i+1...16).each do |j|
      b[j] -= 1 if b[i] < b[j]
    end
  end
  16.times.reduce(0){ |sum, i| sum += b[i] * Factorials[i] }
end
 
def dehash(key)
  brd = 16.times.map { |i| d, key = key.divmod(Factorials[i]); d }
  15.downto(0) do |i|
    (i+1...16).each do |j|
      brd[j] += 1 if brd[j] >= brd[i]
    end
  end
  brd
end

def judge(brd, c)
  ret = c
  16.times do |i|
    if brd[i] > 0
      [R, C].each do |a|
        ret += (a[i] - a[brd[i] - 1]).abs
      end
    end
  end
  ret
end

brd = 4.times.map{ gets.split.map(&:to_i) }.flatten
$heap = []
$n = 0
insert [judge(brd, 0), k = create_hash(brd), 0]
set = Set.new([])
set.add(k)
while $n > 0
  val, key, cnt = extract
  next if val > 45
  if val == cnt
    p cnt
    break
  end
  b = dehash(key)
  n = b.index(0)
  Move[n].each do |m|
    b[n], b[m] = b[m], b[n]
    k = create_hash(b)
    unless set.include?(k)
      set.add(k)
      insert [judge(b, cnt+1), k, cnt + 1]
    end
    b[n], b[m] = b[m], b[n]
  end
end