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