#include <bits/stdc++.h>
using namespace std;
string s;
bool cant;
int n;
int move(int i, int j) {
  if (i == j) return 0;
  if (i || s[i + 1] != '0') {
    swap(s[i], s[i + 1]);
    return 1 + move(i + 1, j);
  } else {
    int k = i + 1;
    while (k < n && s[k] == '0') k++;
    if (k == n) {
      cant = true;
      return 0;
    }
    swap(s[k], s[i + 1]);
    int a = k - i - 1;
    return a + move(i, j);
  }
  return 0;
}
int check(char x, char y) {
  int ans = 0;
  int i = n - 1;
  while (1) {
    if (s[n - 1] == y) break;
    while (i >= 0 && s[i] != y) i--;
    if (i < 0) return -1;
    int a = move(i, n - 1);
    if (cant) {
      i--;
      cant = false;
      continue;
    } else {
      ans += a;
      break;
    }
  }
  i = n - 2;
  while (1) {
    if (s[n - 2] == x) break;
    while (i >= 0 && s[i] != x) i--;
    if (i < 0) return -1;
    int a = move(i, n - 2);
    if (cant) {
      i--;
      cant = false;
      continue;
    } else {
      ans += a;
      break;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  int ans = 1e5, a;
  string s1;
  cin >> (s1);
  ;
  n = s1.size();
  cant = false;
  s = s1;
  if ((a = check('0', '0')) != -1) ans = min(ans, a);
  s = s1;
  if ((a = check('2', '5')) != -1) ans = min(ans, a);
  s = s1;
  if ((a = check('5', '0')) != -1) ans = min(ans, a);
  s = s1;
  if ((a = check('7', '5')) != -1) ans = min(ans, a);
  cout << (ans == 1e5 ? -1 : ans) << endl;
  return 0;
}
