#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long n;
string str;
int a[5][3];
int main() {
  cin >> str;
  int len = str.length();
  reverse(str.begin(), str.end());
  int flag0 = 0, flag5 = 0;
  memset(a, inf, sizeof(a));
  for (int i = 0; i < len; i++) {
    if (str[i] == '2') {
      if (a[1][2] == inf) a[1][2] = i - 1;
    } else if (str[i] == '0') {
      if (a[2][2] != inf && a[2][1] == inf) {
        a[2][1] = i + 1;
      } else if (a[2][1] == inf) {
        a[2][1] = i;
      }
      if (a[4][1] == inf) {
        a[4][1] = i;
      } else if (a[4][2] == inf)
        a[4][2] = i - 1;
    } else if (str[i] == '5') {
      if (a[1][2] != inf && a[1][1] == inf) {
        a[1][1] = i + 1;
      } else if (a[1][1] == inf) {
        a[1][1] = i;
      }
      if (a[2][2] == inf) a[2][2] = i - 1;
      if (a[3][2] != inf && a[3][1] == inf) {
        a[3][1] = i + 1;
      } else if (a[3][1] == inf) {
        a[3][1] = i;
      }
    } else if (str[i] == '7') {
      if (a[3][2] == inf) a[3][2] = i - 1;
    }
  }
  int ans = -1;
  for (int i = 1; i <= 4; i++) {
    if (a[i][1] != inf && a[i][2] != inf && (i == 1 || i == 3)) {
      char q, w;
      int id = i;
      if (id == 1) q = '2', w = '5';
      if (id == 3) q = '7', w = '5';
      int tot = 0;
      int flag1 = 0, flag2 = 0;
      for (int i = 0; i < len; i++) {
        if (q == str[i] && i != len - 1) flag1 = 1;
        if (w == str[i] && i != len - 1) flag2 = 1;
      }
      if (flag1 == 0 || flag2 == 0)
        for (int i = len - 1; i >= 0; i--) {
          if (str[i] != q && str[i] != w && str[i] != '0') break;
          if (str[i] == '0') tot++;
        }
      int tmp = a[i][1] + a[i][2] + tot;
      if (ans == -1)
        ans = tmp;
      else
        ans = min(ans, tmp);
    } else if (a[i][1] != inf && a[i][2] != inf) {
      char q, w;
      q = '5', w = '0';
      int tot = 0;
      int flag1 = 0, flag2 = 0;
      int tt = 0;
      for (int i = 0; i < len; i++) {
        if (q == str[i] && i != len - 1) flag1 = 1;
        if (w == str[i] && i != len - 1) tt++;
      }
      if (i == 4 || tt == 1) flag1 = 1, flag2 = 1;
      if (flag1 == 0 || flag2 == 0) {
        for (int i = len - 1; i >= 0; i--) {
          if (str[i] != q && str[i] != '0') break;
          if (str[i] == '0') tot++;
        }
        tot--;
      }
      int tmp = a[i][1] + a[i][2] + tot;
      if (ans == -1)
        ans = tmp;
      else
        ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
