#include <bits/stdc++.h>
using namespace std;
long long int arr[100], ne[15];
long long int fun(long long int a, long long int b, long long int nb) {
  long long int i, c, k, t, f;
  long long int ans = 1e9;
  if (ne[a] == 1e9 || ne[b] == 1e9) return 1e9;
  if (ne[a] < ne[b]) {
    ans = ne[a] - 1 + ne[b] - 2;
  } else
    ans = ne[a] + ne[b] - 2;
  c = 1;
  for (i = nb; i > 0; i--) {
    if (i != ne[a] && i != ne[b]) {
      if (arr[i] == 0) {
        c = 0;
        k = i;
        break;
      } else
        break;
    }
  }
  if (c == 0) {
    f = 0;
    for (i = nb; i > 0; i--) {
      if (i != ne[a] && i != ne[b] && arr[i] != 0) {
        f = 1;
        t = i;
        break;
      }
    }
    if (f)
      ans += k - t;
    else
      ans = 1e9;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, x, p, i, ans;
  cin >> n;
  x = n;
  p = 0;
  while (x) {
    arr[p + 1] = x % 10;
    x = x / 10;
    p++;
  }
  for (i = 0; i < 10; i++) ne[i] = 1e9;
  for (i = 1; i <= p; i++) {
    ne[arr[i]] = min(ne[arr[i]], i);
  }
  ans = 1e9;
  for (i = ne[0] + 1; i <= p; i++) {
    if (arr[i] == 0) {
      ans = ne[0] + i - 3;
      break;
    }
  }
  ans = min(ans, fun(5, 2, p));
  ans = min(ans, fun(5, 7, p));
  ans = min(ans, fun(0, 5, p));
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
