a = list(input()) b = set(a) def start_1_3(l): if len(l)>1: if l[0]=='1' and l[1]=='3': return True else: return False else: return False def count_3(l, s): if len(s) == 2: return len(l)-1 else: return '-1' if start_1_3(a): print(count_3(a, b)) else: print(-1)