#include <bits/stdc++.h>
using namespace std;
string t;
int make(char a, char b) {
  string s = t;
  int res = 0;
  bool m1 = 0, m2 = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == b) {
      m1 = true;
      for (int j = i; j + 1 < s.length(); j++) {
        swap(s[j], s[j + 1]);
        res++;
      }
      break;
    }
  }
  for (int i = s.length() - 2; i >= 0; i--) {
    if (s[i] == a) {
      m2 = true;
      for (int j = i; j + 1 < s.length() - 1; j++) {
        swap(s[j], s[j + 1]);
        res++;
      }
      break;
    }
  }
  if (!m1 || !m2) return 1e9;
  if (s[0] == '0') {
    for (int i = 0; i < s.length() - 2; i++) {
      if (s[i] != '0') return res + (i);
    }
    return 1e9;
  }
  return res;
}
int main() {
  cin >> t;
  int ans = 1e9;
  ans = min(make('2', '5'), ans);
  ans = min(make('5', '0'), ans);
  ans = min(ans, make('7', '5'));
  ans = min(ans, make('0', '0'));
  if (ans == 1e9) {
    puts("-1");
  } else {
    cout << ans << endl;
  }
  return 0;
}
