#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(10);
string n, temp_n;
int ans, k;
int custoEmpurrar(int posicaoInicial, int posicaoFinal) {
  int dist = 0;
  dist += (posicaoInicial - posicaoFinal);
  swap(n[posicaoFinal], n[posicaoInicial]);
  for (int i = 1; i < 10; ++i) {
    if (v[i].size() && (posicaoInicial > v[i][0])) {
      v[i][0]++;
    }
  }
  int t = k;
  if (t == 2) {
    return dist;
  }
  if (posicaoInicial == (k - 1)) {
    for (int z = 1; z < t; z++) {
      char teste_char = n[z];
      if (n[z] == '0') {
        dist++;
      } else {
        break;
      }
    }
  }
  return dist;
}
int main() {
  cin >> n;
  k = n.size();
  for (int i = k - 1; i >= 0; i--) {
    v[n[i] - '0'].push_back(k - i - 1);
  }
  int dd2[] = {0, 5, 7, 2};
  int dd1[] = {0, 0, 5, 5};
  ans = 9999999;
  int possible[] = {-1, -1, -1, -1};
  for (int i = 0; i < 4; i++) {
    int d1, d2;
    d1 = dd1[i];
    d2 = dd2[i];
    int dist = 0;
    if (i == 0) {
      if (v[0].size() >= 2) {
        dist += v[0][0];
        dist += v[0][1] - 1;
      } else {
        continue;
      }
    } else {
      if (v[d1].size() && v[d2].size()) {
        vector<vector<int> > temp = v;
        temp_n = n;
        int c1 = custoEmpurrar(v[d1][0], 0);
        int c2 = custoEmpurrar(v[d2][0], 1);
        dist += (c1 + c2);
        v = temp;
        n = temp_n;
      } else {
        continue;
      }
    }
    possible[i] = dist;
    ans = min(ans, dist);
  }
  if (ans != 9999999)
    cout << ans << endl;
  else
    cout << "-1\n";
  return 0;
}
