#include <bits/stdc++.h>
const int mo = 1000000007;
const int inf = 0x3f3f3f3f;
double pi = 3.14159265358979323846;
double e = 2.71828182845904523536;
using namespace std;
string a, s;
int n;
int fun(char x, char b) {
  a = s;
  int sum = 0;
  int f1 = 0, f2 = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == b) {
      f1 = 1;
      for (int j = i + 1; j < n; j++) {
        swap(a[j - 1], a[j]);
        ++sum;
      }
      break;
    }
  }
  if (f1 == 0) return inf;
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] == x) {
      f2 = 1;
      for (int j = i + 1; j <= n - 2; j++) {
        swap(a[j - 1], a[j]);
        ++sum;
      }
      break;
    }
  }
  if (f1 && f2) {
    if (a[0] == '0')
      for (int i = 1; i < n - 2; i++) {
        if (a[i] != '0') {
          swap(a[0], a[i]);
          sum += i;
          break;
        }
      }
    return sum;
  } else
    return inf;
}
int main() {
  cin >> s;
  n = s.size();
  int ans = inf;
  ans = min(ans, fun('2', '5'));
  ans = min(ans, fun('5', '0'));
  ans = min(ans, fun('7', '5'));
  ans = min(ans, fun('0', '0'));
  if (ans == inf)
    cout << -1;
  else
    cout << ans;
  return 0;
}
