tt = [0]*17
q = []
res = [-1]*100
(0..600).each do |i|
  break if q.empty? && res.all?{ |v| v != -1 }
  tt.map!{|j| j - 1 }
  unless q.empty?
    idx = 0
    while idx < 17
      break if q.empty?
      x = q[0][1] 
      cnt = 0
      tt[idx..-1].each do |t|
        break if cnt == x
        if t <= 0 then cnt += 1
        elsif t > 0 then cnt = 0
        end
        idx += 1
      end
      if cnt == x 
        y = q.shift
        tt.fill(y[2],idx-x,x)
        res[y[0]] = i - y[3]
      end
    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?
      cnt = idx = 0
      tt.each do |t|
        break if cnt == m
        if t <= 0 then cnt += 1
        elsif t > 0 then cnt = 0
        end
        idx += 1
      end

      if cnt == m
        tt.fill(eat, idx-m, 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