#!/usr/bin/env ruby

require 'prime'

loop do
  n = gets.chomp!.to_i
  break if n.zero?

  number = (2..n).reduce(:*)
  ar = []
  number.prime_division.each do |prm, cnt|
    if prm == 2 || prm == 5
      ar << cnt
    end
  end

  ar << 0 if ar.length != 2
  puts ar.min
end