def search(arr, n, idx)
  (idx..17-n).each do |t|
    return t if arr[t, n].all?{|v| v <= 0}
  end
  nil
end

tt = [0]*17
q = []
res = [-1]*100
(0..1000).each do |i|
  break if q.empty? && res.all?{ |v| v != -1 }
  tt.map!{|j| j - 1 }
  until q.empty?
    idx = 0
    if t = search(tt, x = q[0][1], idx)
      id, n, c, s = q.shift
      tt.fill(c, t, x)
      res[id] = i - s
      idx = t + x
    else break
    end
  end
  if i % 5 == 0 && i < 500
    m = ((i/5)%5 == 1 ? 5 : 2)
    eat = 17 * ((i/5)%2) + 3 * ((i/5)%3) + 19
    if q.empty?
      if t = search(tt, m, 0)
        tt.fill(eat, t, m)
        res[i/5] = 0
      else
        q << [i/5, m, eat, i]
      end
    else q << [i/5, m, eat, i]
    end
  end
end
while gets
  p res[$_.to_i]
end