#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  vector<long long> v;
  long long a_2, a_5, b_0, b_5, c_7, c_5, d_0, d_01, i, k, len;
  cin >> s;
  reverse(s.begin(), s.end());
  len = s.length();
  long long maxx = 1e7;
  long long min_25 = maxx, min_50 = maxx, min_75 = maxx, min_00 = maxx;
  a_2 = s.find("2");
  a_5 = s.find("5");
  b_5 = s.find("5");
  b_0 = s.find("0");
  c_7 = s.find("7");
  c_5 = s.find("5");
  d_0 = s.find("0");
  if (d_0 != -1) {
    d_01 = s.substr(d_0 + 1, s.length()).find("0");
    if (d_01 != -1) {
      d_01 = d_01 + d_0 + 1;
    }
  } else
    d_01 = -1;
  if (a_2 != -1 && a_5 != -1) {
    if (a_5 < a_2)
      min_25 = a_5 + (a_2 - 1);
    else
      min_25 = a_5 + a_2;
    if (a_5 == (len - 1) && s[len - 2] == '0') {
      k = 0;
      for (i = len - 2; i >= 0; i--) {
        if (s[i] != '0') break;
        k++;
      }
      if (i == a_2 && (i - 1) >= 0 && s[i - 1] == '0') {
        for (i = a_2 - 1; i >= 0; i--) {
          if (s[i] != '0') break;
          k++;
        }
      }
      min_25 += k;
    } else if (a_2 == s.length() - 1 && s[s.length() - 2] == '0') {
      k = 0;
      for (i = s.length() - 2; i >= 0; i--) {
        if (s[i] != '0') break;
        k++;
      }
      if (i == a_5 && (i - 1) >= 0 && s[i - 1] == '0') {
        for (i = a_5 - 1; i >= 0; i--) {
          if (s[i] != '0') break;
          k++;
        }
      }
      min_25 += k;
    }
  }
  if (b_5 != -1 && b_0 != -1) {
    if (b_0 < a_5)
      min_50 = b_0 + (b_5 - 1);
    else
      min_50 = b_0 + b_5;
  }
  if (c_7 != -1 && c_5 != -1) {
    if (c_5 < c_7)
      min_75 = c_5 + (c_7 - 1);
    else
      min_75 = c_5 + c_7;
    if (c_5 == s.length() - 1 && s[s.length() - 2] == '0') {
      k = 0;
      for (i = s.length() - 2; i >= 0; i--) {
        if (s[i] != '0') break;
        k++;
      }
      if (i == c_7 && (i - 1) >= 0 && s[i - 1] == '0') {
        for (i = c_7 - 1; i >= 0; i--) {
          if (s[i] != '0') break;
          k++;
        }
      }
      min_75 += k;
    } else if (c_5 == s.length() - 1 && s[s.length() - 2] == '0') {
      k = 0;
      for (i = s.length() - 2; i >= 0; i--) {
        if (s[i] != '0') break;
        k++;
      }
      if (i == c_7 && (i - 1) >= 0 && s[i - 1] == '0') {
        for (i = c_7 - 1; i >= 0; i--) {
          if (s[i] != '0') break;
          k++;
        }
      }
      min_75 += k;
    }
  }
  if (d_0 != -1 && d_01 != -1) {
    min_00 = d_0 + d_01 - 1;
  }
  v.push_back(min_25);
  v.push_back(min_50);
  v.push_back(min_75);
  v.push_back(min_00);
  sort(v.begin(), v.end());
  if (v[0] >= maxx) v[0] = -1;
  cout << v[0] << "\n";
  return 0;
}
