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;
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;
}