n = input() if n[0] != '1' or set(n[1:]) != {'3'}: print(-1) else: print(n.count('3'))