#include <bits/stdc++.h>
using namespace std;
inline bool check(string &s) {
  long long n = s.size(), x = 0;
  for (int i = 0; i < n; ++i) x = x * 10 + s[i] - '0';
  return x % 25 == 0;
}
inline int Get(string &s, int n, int b = 9999) {
  if (b != 9999) b = s.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] - '0' == n && i != b) return i;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  string s;
  cin >> s;
  if (check(s)) {
    cout << 0 << '\n';
    return 0;
  }
  int n = s.size();
  priority_queue<int> Q[10];
  vector<int> v(4, 1e9);
  for (int i = 0; i < n; ++i) Q[s[i] - '0'].push(i);
  if (Q[0].empty() && Q[2].empty() && Q[5].empty() && Q[7].empty()) {
    cout << -1 << '\n';
    return 0;
  }
  if (Q[0].size() >= 2) {
    int a = Q[0].top();
    Q[0].pop();
    int b = Q[0].top();
    Q[0].push(a);
    swap(a, b);
    int counter = 0, j;
    string temp = s;
    for (j = b; j < n - 1; ++j) {
      swap(temp[j], temp[j + 1]);
      counter++;
      if (check(temp)) {
        v[0] = counter;
        break;
      }
    }
    b = j;
    a = Get(temp, 0, b);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[0] = counter;
        break;
      }
    }
    v[0] = counter;
    int i = 0;
    while (temp[i++] == '0') v[0]++;
  }
  if (Q[2].size() && Q[5].size()) {
    int a = Q[2].top();
    int b = Q[5].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[1] = counter;
        break;
      }
    }
    a = Get(temp, 2);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[1] = counter;
        break;
      }
    }
    v[1] = counter;
    int i = 0;
    while (temp[i++] == '0') v[1]++;
  }
  if (Q[5].size() && Q[0].size()) {
    int a = Q[5].top();
    int b = Q[0].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[2] = counter;
        break;
      }
    }
    a = Get(temp, 5);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[2] = counter;
        break;
      }
    }
    v[2] = counter;
    int i = 0;
    while (temp[i++] == '0') v[2]++;
  }
  if (Q[5].size() && Q[7].size()) {
    int a = Q[7].top();
    int b = Q[5].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[3] = counter;
        break;
      }
    }
    a = Get(temp, 7);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[3] = counter;
        break;
      }
    }
    v[3] = counter;
    int i = 0;
    while (temp[i++] == '0') v[3]++;
  }
  int ans = *min_element(v.begin(), v.end());
  cout << (ans == 1e9 ? -1 : ans) << '\n';
  return 0;
}
