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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class _988E {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    Solver solver = new Solver();
    solver.solve(in, out);
    out.close();
  }

  private static class Solver {
    private String text;

    private void solve(InputReader in, PrintWriter out) {
      long n = in.nextLong();
      if (n < 10) {
        if (n == 0) {
          out.println(0);
        } else {
          out.println(-1);
        }
        return;
      }

      String number = String.valueOf(n);
      String[] lastDigit = new String[] { "00", "25", "50", "75" };

      int ans = -1;
      for (int i = 0; i < lastDigit.length; i++) {
        int tmp = numOfMove(number, lastDigit[i]);
        if (tmp != -1 && (ans == -1 || ans > tmp)) {
          ans = tmp;
        }
      }

      out.println(ans);
    }

    private int numOfMove(String number, String lastDigit) {
      char d1 = lastDigit.charAt(0);
      char d2 = lastDigit.charAt(1);
      int ans = -1;

      // move d2 first then d1
      text = number;
      int tmpAns1 = -1;
      int tmpAns2 = -1;
      for (int i = text.length() - 1; i >= 0; i--) {
        if (text.charAt(i) == d2) {
          tmpAns1 = moveDigit(i, text.length() - 1);
          break;
        }
      }
      for (int i = text.length() - 2; i >= 0; i--) {
        if (text.charAt(i) == d1) {
          tmpAns2 = moveDigit(i, text.length() - 2);
          break;
        }
      }

      if (tmpAns1 != -1 && tmpAns2 != -1) {
        ans = tmpAns1 + tmpAns2;
      }

      // move d1 first then d2
      text = number;
      tmpAns1 = -1;
      tmpAns2 = -1;
      for (int i = text.length() - 2; i >= 0; i--) {
        if (text.charAt(i) == d1) {
          tmpAns1 = moveDigit(i, text.length() - 2);
          break;
        }
      }
      for (int i = text.length() - 1; i >= 0; i--) {
        if (i != text.length() - 2 && text.charAt(i) == d2) {
          tmpAns2 = moveDigit(i, text.length() - 1);
          if (tmpAns2 != -1 && i == text.length() - 1) {
            tmpAns2++;
          }
          break;
        }
      }

      if (tmpAns1 != -1 && tmpAns2 != -1) {
        if (ans == -1 || ans > tmpAns1 + tmpAns2) {
          ans = tmpAns1 + tmpAns2 + 1;
        }
      }

      return ans;
    }

    private int moveDigit(int from, int to) {
      int move = 0;
      if (from == 0 && text.charAt(1) == '0' && to != from) {
        boolean valid = false;
        for (int i = 2; i < text.length(); i++) {
          if (text.charAt(i) != '0') {
            StringBuilder sb = new StringBuilder(text);
            for (int j = i; j > 0; j--) {
              char l = sb.charAt(j);
              char r = sb.charAt(j - 1);
              sb.setCharAt(j, r);
              sb.setCharAt(j - 1, l);
              move++;
            }
            text = sb.toString();
            valid = true;
            break;
          }
        }
        if (!valid) {
          return -1;
        } else {
          from++;
        }
      }

      StringBuilder sb = new StringBuilder(text);
      for (int i = from; i < to; i++) {
        char l = sb.charAt(i);
        char r = sb.charAt(i + 1);
        sb.setCharAt(i, r);
        sb.setCharAt(i + 1, l);
        move++;
      }
      text = sb.toString();

      return move;
    }
  }

  private static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    private InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    private String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    private int nextInt() {
      return Integer.parseInt(next());
    }

    private long nextLong() {
      return Long.parseLong(next());
    }
  }
}