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>
const int MAXN = (int)5e5 + 10;
const int MODN = (int)1e9 + 7;
int inf = 0x3f3f3f3f;
using namespace std;
char str[20];
int a[11];
int main() {
  while (scanf("%s", str) != EOF) {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < strlen(str); i++) {
      int index = str[i] - '0';
      a[index]++;
    }
    int sum1 = 1000, sum2 = 1000, sum3 = 1000, sum4 = 1000;
    if (a[0] >= 2) {
      sum1 = 0;
      int flag = 0;
      int len = strlen(str);
      for (int i = len - 1; i >= 0; i--) {
        int num = str[i] - '0';
        if (num == 0 && flag == 0) {
          sum1 += len - 1 - i;
          flag = 1;
        } else if (num == 0 && flag == 1) {
          sum1 += len - 2 - i;
          break;
        }
      }
    }
    if (a[2] != 0 && a[5] != 0) {
      sum2 = 0;
      int len = strlen(str);
      int flag2 = 0;
      int flag5 = 0;
      int index0 = -1;
      int index2 = -1;
      int index5 = -1;
      for (int i = len - 1; i >= 0; i--) {
        int num = str[i] - '0';
        if (num == 5 && flag5 == 0) {
          sum2 += len - 1 - i;
          flag5 = 1;
          index5 = i;
        } else if (num == 2 && flag2 == 0) {
          if (flag5 == 0) {
            sum2++;
          }
          sum2 += len - 2 - i;
          flag2 = 1;
          index2 = i;
        }
        if (flag2 == 1 && flag5 == 1) {
          break;
        }
      }
      if (a[0] > 0) {
        for (int i = 0; i < len; i++) {
          int num = str[i] - '0';
          if (num != 0 && i != index5 && i != index2) {
            index0 = i;
            break;
          }
        }
        if (index0 > index2 && index0 < index5 ||
            index0 < index2 && index0 > index5) {
          sum2 += (index0 - 1);
        } else if (index0 > index2 && index0 > index5) {
          sum2 += (index0 - 2);
        }
      }
    }
    if (a[5] != 0 && a[0] != 0) {
      sum3 = 0;
      int len = strlen(str);
      int flag5 = 0;
      int index5 = -1;
      int flag0 = 0;
      int index0 = -1;
      int index = -1;
      for (int i = len - 1; i >= 0; i--) {
        int num = str[i] - '0';
        if (num == 0 && flag0 == 0) {
          sum3 += len - 1 - i;
          flag0 = 1;
          index0 = i;
        } else if (num == 5 && flag5 == 0) {
          if (flag0 == 0) {
            sum3++;
          }
          sum3 += len - 2 - i;
          flag5 = 1;
          index5 = i;
        }
        if (flag0 == 1 && flag5 == 1) {
          break;
        }
      }
      if (a[0] > 1) {
        for (int i = 0; i < len; i++) {
          int num = str[i] - '0';
          if (num != 0 && i != index5 && i != index0) {
            index = i;
            break;
          }
        }
        if (index > index0 && index < index5 ||
            index < index0 && index > index5) {
          sum3 += (index - 1);
        } else if (index > index0 && index > index5) {
          sum3 += (index - 2);
        }
      }
    }
    if (a[7] != 0 && a[5] != 0) {
      sum4 = 0;
      int len = strlen(str);
      int flag7 = 0;
      int flag5 = 0;
      int index0 = -1;
      int index5 = -1;
      int index7 = -1;
      for (int i = len - 1; i >= 0; i--) {
        int num = str[i] - '0';
        if (num == 5 && flag5 == 0) {
          sum4 += len - 1 - i;
          flag5 = 1;
          index5 = i;
        } else if (num == 7 && flag7 == 0) {
          if (flag5 == 0) {
            sum4++;
          }
          sum4 += len - 2 - i;
          flag7 = 1;
          index7 = i;
        }
        if (flag7 == 1 && flag5 == 1) {
          break;
        }
      }
      if (a[0] > 0) {
        for (int i = 0; i < len; i++) {
          int num = str[i] - '0';
          if (num != 0 && i != index5 && i != index7) {
            index0 = i;
            break;
          }
        }
        if (index0 > index7 && index0 < index5 ||
            index0 < index7 && index0 > index5) {
          sum4 += (index0 - 1);
        } else if (index0 > index7 && index0 > index5) {
          sum4 += (index0 - 2);
        }
      }
    }
    if (sum1 == 1000 && sum2 == 1000 && sum3 == 1000 && sum4 == 1000) {
      printf("-1\n");
    } else {
      int minn = 0;
      minn = min(sum1, min(sum2, min(sum3, sum4)));
      printf("%d\n", minn);
    }
  }
}