Problem: You are given an integer n from 1 to 10^{18} without leading zeroes.

In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.

What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.

Input

The first line contains an integer n (1 ≤ n ≤ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.

Output

If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.

Note that you can swap only adjacent digits in the given number.

Examples

Input

5071


Output

4


Input

705


Output

1


Input

1241367


Output

-1

Note

In the first example one of the possible sequences of moves is 5071 → 5701 → 7501 → 7510 → 7150.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
bool ok(char x) {
  if (x == '0' or x == '2' or x == '5' or x == '7') return true;
  return false;
}
int main() {
  string n;
  cin >> n;
  if (n.size() < 2) return puts("-1"), 0;
  map<int, pair<int, int>> v;
  pair<int, int> x;
  x = make_pair(-1, -1);
  v[0] = v[2] = v[5] = v[7] = x;
  for (int i = 0; i < n.size(); i++) {
    if (!ok(n[i])) continue;
    pair<int, int> aux = v[n[i] - '0'];
    vector<int> teste;
    teste.push_back(aux.first);
    teste.push_back(aux.second);
    teste.push_back(i);
    sort(teste.begin(), teste.end());
    v[n[i] - '0'] = make_pair(teste[1], teste[2]);
  }
  vector<int> ans(4, 0);
  int len = n.size();
  if (len == 3 and n[1] == '0') {
    if (n[2] == '0')
      return puts("0"), 0;
    else {
      if (n[0] == '5')
        return puts("2"), 0;
      else if (n[2] == '5')
        return puts("1"), 0;
      else
        return puts("-1"), 0;
    }
  }
  if (v[0].first == -1)
    ans[0] = 100000000;
  else {
    ans[0] = -(v[0].second - len + 1) + -(v[0].first - len + 2);
  }
  if (v[2].second == -1 or v[5].second == -1)
    ans[1] = 100000000;
  else {
    if (n[1] == '0' and (v[2].second == 0 or v[5].second == 0)) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      ans[1] = kkk - 1;
      if (v[2].second == kkk) {
        if (kkk = len - 1)
          ans[1] = 100000000;
        else {
          v[2].second = 1;
        }
      } else if (v[5].second == kkk) {
        if (kkk = len - 1)
          ans[1] = 100000000;
        else {
          v[5].second = 1;
        }
      }
    }
    ans[1] += -(v[2].second - len + 2) + -(v[5].second - len + 1) +
              (v[5].second < v[2].second ? 1 : 0);
  }
  if (v[5].second == -1 or v[0].second == -1)
    ans[2] = 100000000;
  else {
    if (n == "50") return puts("0"), 0;
    if (n[1] == '0' and v[5].second == 0) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      if (!ajuda)
        ans[2] = 100000000;
      else {
        if (v[0].second < kkk) v[0].second = kkk;
        ans[2] = kkk - 1;
      }
    }
    ans[2] += -(v[5].second - len + 2) + -(v[0].second - len + 1) +
              (v[0].second < v[5].second ? 1 : 0);
  }
  if (v[7].second == -1 or v[5].second == -1)
    ans[3] = 100000000;
  else {
    if (n[1] == '0' and (v[7].second == 0 or v[5].second == 0)) {
      bool ajuda = false;
      int kkk;
      for (kkk = 2; kkk < len; kkk++) {
        if (n[kkk] == '0') continue;
        ajuda = true;
        break;
      }
      ans[3] = kkk - 1;
      if (v[7].second == kkk) {
        if (kkk = len - 1)
          ans[3] = 100000000;
        else {
          v[7].second = 1;
        }
      } else if (v[5].second == kkk) {
        if (kkk = len - 1)
          ans[3] = 100000000;
        else {
          v[5].second = 1;
        }
      }
    }
    ans[3] += -(v[7].second - len + 2) + -(v[5].second - len + 1) +
              (v[5].second < v[7].second ? 1 : 0);
  }
  int resp = 100000000;
  for (int i = 0; i < 4; i++) resp = min(resp, ans[i]);
  if (resp >= 100000000)
    puts("-1");
  else
    cout << resp << endl;
  return 0;
}