#include <bits/stdc++.h>
using namespace std;
map<char, int> mapas;
string a;
const int inf = 1e9;
int f(char k, char d) {
  string b = a;
  int galima = 0;
  int ret = 0;
  for (int j = b.size() - 1; j > -1; j--) {
    if (b[j] == d) {
      ret += b.size() - 1 - j;
      b.erase(j, 1);
      b.push_back(j);
      galima += 1;
      break;
    }
  }
  for (int j = b.size() - 2; j > -1; j--) {
    if (b[j] == k) {
      ret += b.size() - 2 - j;
      galima += 1;
      break;
    }
  }
  for (int j = 0; j < b.size() - 2; j++) {
    if (b[j] != '0') {
      galima += 1;
      ret += j;
      break;
    }
  }
  if (a.size() == 2) galima++;
  if (galima != 3) return inf;
  return ret;
}
int main() {
  cin >> a;
  if (a.size() == 1) {
    cout << -1;
    return 0;
  }
  for (auto x : a) mapas[x]++;
  int ans = min(min(f('0', '0'), f('2', '5')), min(f('7', '5'), f('5', '0')));
  if (ans == inf) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
