#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, INF = 1e10, mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long z = 0, f = 0, s = 0, t = 0;
  string n;
  cin >> n;
  long long len = n.length();
  for (int i = 0; i < len; i++) {
    if (n[i] == '0') {
      z++;
    }
    if (n[i] == '5') {
      f++;
    }
    if (n[i] == '2') {
      t++;
    }
    if (n[i] == '7') {
      s++;
    }
  }
  if (z < 2 && (z < 1 || f < 1) && (t < 1 || f < 1) && (s < 1 || f < 1)) {
    cout << -1;
    return 0;
  }
  reverse(n.begin(), n.end());
  string cur = n;
  long long ans = INF, cnt = 0;
  if (z >= 2) {
    if (cur[0] != '0') {
      for (int i = 1; i < len; i++) {
        if (cur[i] == '0') {
          long long pos = i;
          while (pos) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[1] != '0') {
      for (int i = 2; i < len; i++) {
        if (cur[i] == '0') {
          long long pos = i;
          while (pos > 1) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[len - 1] == '0') {
      for (int i = len - 2; i >= 0; i--) {
        if (cur[i] != '0') {
          long long pos = i;
          while (pos < len - 1) {
            swap(cur[pos], cur[pos + 1]);
            pos++;
            cnt++;
          }
          break;
        }
      }
    }
    reverse(cur.begin(), cur.end());
    if (stoll(cur) % 25 == 0) {
      ans = min(ans, cnt);
    }
    cnt = 0;
  }
  cur = n;
  if (!(z < 1 || f < 1)) {
    if (cur[0] != '0') {
      for (int i = 1; i < len; i++) {
        if (cur[i] == '0') {
          long long pos = i;
          while (pos) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[1] != '5') {
      for (int i = 2; i < len; i++) {
        if (cur[i] == '5') {
          long long pos = i;
          while (pos > 1) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[len - 1] == '0') {
      for (int i = len - 2; i >= 0; i--) {
        if (cur[i] != '0') {
          long long pos = i;
          while (pos < len - 1) {
            swap(cur[pos], cur[pos + 1]);
            pos++;
            cnt++;
          }
          break;
        }
      }
    }
    reverse(cur.begin(), cur.end());
    if (stoll(cur) % 25 == 0) {
      ans = min(ans, cnt);
    }
    cnt = 0;
  }
  cur = n;
  if (!(t < 1 || f < 1)) {
    if (cur[0] != '5') {
      for (int i = 1; i < len; i++) {
        if (cur[i] == '5') {
          long long pos = i;
          while (pos) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[1] != '2') {
      for (int i = 2; i < len; i++) {
        if (cur[i] == '2') {
          long long pos = i;
          while (pos > 1) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[len - 1] == '0') {
      for (int i = len - 2; i >= 0; i--) {
        if (cur[i] != '0') {
          long long pos = i;
          while (pos < len - 1) {
            swap(cur[pos], cur[pos + 1]);
            pos++;
            cnt++;
          }
          break;
        }
      }
    }
    reverse(cur.begin(), cur.end());
    if (stoll(cur) % 25 == 0) {
      ans = min(ans, cnt);
    }
    cnt = 0;
  }
  cur = n;
  if (!(s < 1 || f < 1)) {
    if (cur[0] != '5') {
      for (int i = 1; i < len; i++) {
        if (cur[i] == '5') {
          long long pos = i;
          while (pos) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[1] != '7') {
      for (int i = 2; i < len; i++) {
        if (cur[i] == '7') {
          long long pos = i;
          while (pos > 1) {
            swap(cur[pos], cur[pos - 1]);
            pos--;
            cnt++;
          }
          break;
        }
      }
    }
    if (cur[len - 1] == '0') {
      for (int i = len - 2; i >= 0; i--) {
        if (cur[i] != '0') {
          long long pos = i;
          while (pos < len - 1) {
            swap(cur[pos], cur[pos + 1]);
            pos++;
            cnt++;
          }
          break;
        }
      }
    }
    reverse(cur.begin(), cur.end());
    if (stoll(cur) % 25 == 0) {
      ans = min(ans, cnt);
    }
    cnt = 0;
  }
  cout << ans;
}
