#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> dig;
  long long int m = n;
  while (m > 0) {
    dig.push_back(m % 10);
    m /= 10;
  }
  long long int t_0 = -1, t_5 = -1;
  for (long long int i = 0; i < (long long int)dig.size(); i++) {
    if (dig[i] == 0) {
      t_0 = i;
      long long int first = 0;
      for (long long int j = 0; j < (long long int)dig.size(); j++) {
        if (j == i) continue;
        if (dig[j] == 0 || dig[j] == 5) {
          if (j > i)
            t_0 += j - 1;
          else
            t_0 += j;
          first = 1;
          break;
        }
      }
      if (!first) t_0 = -1;
      break;
    }
  }
  vector<long long int> idx;
  for (long long int i = 0; i < dig.size(); i++) {
    if (dig[i] == 5) {
      t_5 = i;
      idx.push_back(i);
      long long int first = 0;
      for (long long int j = 0; j < dig.size(); j++) {
        if (j == i) continue;
        if (dig[j] == 2 || dig[j] == 7) {
          if (j > i)
            t_5 += j - 1;
          else
            t_5 += j;
          idx.push_back(j);
          first = 1;
          break;
        }
      }
      if (!first) t_5 = -1;
      break;
    }
  }
  if (t_5 != -1) {
    long long int first = 0;
    vector<long long int> x;
    for (long long int i = 0; i < dig.size(); i++) {
      if (i != idx[0] && i != idx[1]) x.push_back(dig[i]);
    }
    for (long long int i = (long long int)x.size() - 1; i >= 0; i--) {
      if (x[i] != 0) {
        t_5 += (x.size() - 1 - i);
        first = 1;
        break;
      }
    }
    if (!first && x.size() > 0) t_5 = -1;
  }
  vector<long long int> ans;
  if (t_0 != -1) ans.push_back(t_0);
  if (t_5 != -1) ans.push_back(t_5);
  if (!ans.size())
    cout << "-1";
  else
    cout << *min_element(ans.begin(), ans.end());
  return 0;
}
