#include <bits/stdc++.h>
using namespace std;
char d;
int m = INT_MAX;
int t = 0;
int bit = 1;
int bay = 0, st = -1;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int l = s.length();
  vector<int> s0, s2, s5;
  for (int i = l - 1; i >= 0; --i) {
    if (s[i] == '0')
      s0.push_back(l - 1 - i);
    else if (s[i] == '2')
      s2.push_back(l - 1 - i);
    else if (s[i] == '5')
      s5.push_back(l - i - 1);
    else if (s[i] == '7') {
      s[i] = '2';
      s2.push_back(l - 1 - i);
    }
  }
  if (s0.size() > 1) {
    t = 0;
    t += s0[0] + s0[1] - 1;
    if (s5.size() != 0) {
      if (s5[0] > s0[1]) bit = 0;
    }
    if (t < m) m = t;
  } else if (s0.size() != 0 && s5.size() != 0 && bit == 1) {
    t = 0;
    if (s0[0] > s5[0])
      t += s0[0] + s5[0];
    else
      t += s0[0] + s5[0] - 1;
    if (t < m) m = t;
  }
  if (s0.size() == 0 && s5.size() != 0 && s2.size() != 0) {
    t = 0;
    if (s5[0] > s2[0])
      t += s2[0] + s5[0];
    else
      t += s2[0] + s5[0] - 1;
    if (t < m) m = t;
  } else if (s0.size() != 0 && s5.size() != 0 && s2.size() != 0) {
    if (s0[0] > s2[0] && s0[0] < s5[0]) {
      string ss = s;
      t = 0;
      int k2 = l - 1 - s2[0];
      int k5 = l - 1 - s5[0];
      for (int i = k2; i < l - 1; ++i) {
        d = s[i];
        s[i] = s[i + 1];
        s[i + 1] = d;
        t++;
      }
      for (int i = k5; i < l - 1; ++i) {
        d = s[i];
        s[i] = s[i + 1];
        s[i + 1] = d;
        t++;
      }
      for (int i = 0; i < l - 2; ++i) {
        if (s[i] != '0') {
          bay = 1;
          st = i;
          break;
        }
      }
      if (bay == 0)
        t = INT_MAX;
      else
        t = t + st;
      if (t < m) m = t;
      s = ss;
    } else {
      t = 0;
      if (s5[0] > s2[0])
        t += s2[0] + s5[0];
      else
        t += s2[0] + s5[0] - 1;
      if (t < m) m = t;
    }
  }
  if (m == INT_MAX)
    cout << "-1\n";
  else
    cout << m << endl;
}
