#!/usr/bin/env python3
s = input()
ret = len(s)
for i in range(len(s)):
  if s[i] != str(i+1):
    ret = -1
print(ret)