#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  unsigned best = -1, cn = 0;
  cin >> a;
  for (int i = 1; i < a.size() && a[i] == '0'; ++i) cn++;
  for (int i = 0; i < a.size(); i++)
    for (int j = 0; j < a.size(); j++)
      if (i != j) {
        int x = (a[i] - '0') * 10 + a[j] - '0';
        unsigned p = a.size() - j - 1;
        if (i < j)
          p += a.size() - i - 2;
        else
          p += a.size() - i - 1;
        if (j == 0) p += cn;
        if (x % 25 == 0 && p < best) best = p;
      }
  cout << (int)best;
}
