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