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;
inline bool check(string &s) {
  long long n = s.size(), x = 0;
  for (int i = 0; i < n; ++i) x = x * 10 + s[i] - '0';
  return x % 25 == 0;
}
inline int Get(string &s, int n, int b = 9999) {
  if (b != 9999) b = s.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] - '0' == n && i != b) return i;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  string s;
  cin >> s;
  if (check(s)) {
    cout << 0 << '\n';
    return 0;
  }
  int n = s.size();
  priority_queue<int> Q[10];
  vector<int> v(4, 1e9);
  for (int i = 0; i < n; ++i) Q[s[i] - '0'].push(i);
  if (Q[0].empty() && Q[2].empty() && Q[5].empty() && Q[7].empty()) {
    cout << -1 << '\n';
    return 0;
  }
  if (Q[0].size() >= 2) {
    int a = Q[0].top();
    Q[0].pop();
    int b = Q[0].top();
    Q[0].push(a);
    swap(a, b);
    int counter = 0, j;
    string temp = s;
    for (j = b; j < n - 1; ++j) {
      swap(temp[j], temp[j + 1]);
      counter++;
      if (check(temp)) {
        v[0] = counter;
        break;
      }
    }
    b = j;
    a = Get(temp, 0, b);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[0] = counter;
        break;
      }
    }
    v[0] = counter;
    int i = 0;
    while (temp[i++] == '0') v[0]++;
  }
  if (Q[2].size() && Q[5].size()) {
    int a = Q[2].top();
    int b = Q[5].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[1] = counter;
        break;
      }
    }
    a = Get(temp, 2);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[1] = counter;
        break;
      }
    }
    v[1] = counter;
    int i = 0;
    while (temp[i++] == '0') v[1]++;
  }
  if (Q[5].size() && Q[0].size()) {
    int a = Q[5].top();
    int b = Q[0].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[2] = counter;
        break;
      }
    }
    a = Get(temp, 5);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[2] = counter;
        break;
      }
    }
    v[2] = counter;
    int i = 0;
    while (temp[i++] == '0') v[2]++;
  }
  if (Q[5].size() && Q[7].size()) {
    int a = Q[7].top();
    int b = Q[5].top();
    int counter = 0;
    string temp = s;
    for (int i = b; i < n - 1; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[3] = counter;
        break;
      }
    }
    a = Get(temp, 7);
    for (int i = a; i < n - 2; ++i) {
      swap(temp[i], temp[i + 1]);
      counter++;
      if (check(temp)) {
        v[3] = counter;
        break;
      }
    }
    v[3] = counter;
    int i = 0;
    while (temp[i++] == '0') v[3]++;
  }
  int ans = *min_element(v.begin(), v.end());
  cout << (ans == 1e9 ? -1 : ans) << '\n';
  return 0;
}