N = gets.chomp ns = [] (0..100).each do |i| ns << '1' + '3' * i end ans = ns.index(N) puts ans ? ans : -1