#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};
string s;
int come(string a) {
  if (a[0] != '0') return 0;
  int aux = 0;
  for (int i = 0; i < int(a.size()); i++) {
    if (a[i] != '0') return i;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  int a = 0, b = 0, c = 0, d = 0;
  ;
  for (int i = 0; i < int(s.size()); i++) {
    if (s[i] == '0')
      a++;
    else if (s[i] == '2')
      d++;
    else if (s[i] == '5')
      b++;
    else if (s[i] == '7')
      c++;
  }
  bool at = false;
  if (a >= 2 or (d > 0 and b > 0) or (c > 0 and b > 0) or (b > 0 and a > 0))
    at = true;
  if (!at) {
    cout << -1 << "\n";
    return 0;
  }
  int ans = 29292222;
  if (a >= 2) {
    int aux = 0;
    int at = 0;
    string a = s;
    if (a[int(a.size()) - 1] != '0') {
      for (int i = int(a.size()) - 1; i >= 0; i--) {
        if (a[i] == '0') {
          for (int j = i; j < int(a.size()) - 1; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    if (a[int(a.size()) - 2] != '0') {
      for (int i = int(a.size()) - 2; i >= 0; i--) {
        if (a[i] == '0') {
          for (int j = i; j < int(a.size()) - 2; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    aux += come(a);
    ans = min(ans, aux);
  }
  if (d > 0 and b > 0) {
    int aux = 0;
    int at = 0, at2 = 0;
    string a = s;
    if (a[int(a.size()) - 1] != '5') {
      for (int i = int(a.size()) - 1; i >= 0; i--) {
        if (a[i] == '5') {
          for (int j = i; j < int(a.size()) - 1; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    if (a[int(a.size()) - 2] != '2') {
      for (int i = int(a.size()) - 2; i >= 0; i--) {
        if (a[i] == '2') {
          for (int j = i; j < int(a.size()) - 2; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    aux += come(a);
    ans = min(ans, aux);
  }
  if (c > 0 and b > 0) {
    int aux = 0;
    int at = 0, at2 = 0;
    string a = s;
    if (a[int(a.size()) - 1] != '5') {
      for (int i = int(a.size()) - 1; i >= 0; i--) {
        if (a[i] == '5') {
          for (int j = i; j < int(a.size()) - 1; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    if (a[int(a.size()) - 2] != '7') {
      for (int i = int(a.size()) - 2; i >= 0; i--) {
        if (a[i] == '7') {
          for (int j = i; j < int(a.size()) - 2; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    aux += come(a);
    ans = min(ans, aux);
  }
  if (b > 0 and a > 0) {
    int aux = 0;
    int at = 0, at2 = 0;
    string a = s;
    if (a[int(a.size()) - 1] != '0') {
      for (int i = int(a.size()) - 1; i >= 0; i--) {
        if (a[i] == '0') {
          for (int j = i; j < int(a.size()) - 1; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    if (a[int(a.size()) - 2] != '5') {
      for (int i = int(a.size()) - 2; i >= 0; i--) {
        if (a[i] == '5') {
          for (int j = i; j < int(a.size()) - 2; j++) {
            swap(a[j], a[j + 1]);
            aux++;
          }
          break;
        }
      }
    }
    aux += come(a);
    ans = min(ans, aux);
  }
  cout << ans << "\n";
  return 0;
}
