#include <bits/stdc++.h>
using namespace std;
int check(string str, char c1, char c2) {
  int an = 0;
  bool f1 = false;
  bool f2 = false;
  int i;
  for (i = str.length() - 1; i >= 0; i--) {
    if (str.at(i) == c2) {
      f1 = true;
      break;
    }
    an += 2;
  }
  if (!f1) {
    return 1000000007;
  }
  i--;
  for (; i >= 0; i--) {
    if (str.at(i) == c1) {
      f2 = true;
      break;
    }
    an++;
  }
  if (!f2) {
    return 1000000007;
  }
  return an;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string str;
  cin >> str;
  int to5 = -10;
  int to0 = -10;
  for (int i = str.length() - 1; i >= 0; i--) {
    if (str.at(i) == '5' && to5 == -10) {
      to5 = str.length() - 1 - i;
    }
    if (str.at(i) == '0' && to0 == -10) {
      to0 = str.length() - 1 - i;
    }
  }
  if (to5 == -10 && to0 == -10) {
    cout << -1;
    return 0;
  }
  int to00 = -10;
  int to50 = -10;
  int to25 = -10;
  int to75 = -10;
  if (to5 != -10) {
    for (int i = str.length() - 1; i >= 0; i--) {
      if (str.at(i) == '2' && to25 == -10) {
        to25 = str.length() - 2 - i;
      }
      if (str.at(i) == '7' && to75 == -10) {
        to75 = str.length() - 2 - i;
      }
    }
  }
  if (to0 != -10) {
    bool was1 = false;
    for (int i = str.length() - 1; i >= 0; i--) {
      if (str.at(i) == '0' && to00 == -10) {
        if (was1) {
          to00 = str.length() - 2 - i;
        } else {
          was1 = true;
        }
      }
      if (str.at(i) == '5' && to50 == -10) {
        to50 = str.length() - 2 - i;
      }
    }
  }
  if (to00 == -10 && to50 == -10 && to25 == -10 && to75 == -10) {
    cout << -1;
    return 0;
  }
  int ans = 1000000007;
  if (to00 != -10) {
    ans = min(to0 + to00, ans);
  }
  if (to50 != -10) {
    if (to0 > to50) {
      to50++;
    }
    ans = min(to0 + to50, ans);
  }
  if (to25 != -10) {
    if (to5 > to25) {
      to25++;
    }
    if (to5 == str.length() - 1 && str.at(1) == '0') {
      int i = 1;
      while (str.at(i) == '0') {
        i++;
      }
      to25 += i - 1;
    }
    ans = min(to5 + to25, ans);
  }
  if (to75 != -10) {
    if (to5 > to75) {
      to75++;
    }
    if (to5 == str.length() - 1 && str.at(1) == '0') {
      int i = 1;
      while (str.at(i) == '0') {
        i++;
      }
      to75 += i - 1;
    }
    ans = min(to5 + to75, ans);
  }
  cout << ans;
  return 0;
}
