#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 998244353;
const long long maxn = 2e5 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
char S[maxn];
const int N = 5;
struct matrix {
  int A[N][N];
  matrix() { memset(A, 0, sizeof(A)); }
} A[maxn << 2], mat[10];
matrix trans(matrix A, matrix B) {
  matrix C;
  int i, j, k;
  for (i = 0; i < N; i++)
    for (j = 0; j < N; j++) {
      C.A[i][j] = INF;
      for (k = 0; k < N; k++) C.A[i][j] = min(C.A[i][j], A.A[i][k] + B.A[k][j]);
    }
  return C;
}
void build(int x, int L, int R) {
  if (L == R) {
    A[x] = mat[S[L] - '0'];
    return;
  }
  int mid = (L + R) / 2;
  build(x << 1, L, mid);
  build(x << 1 | 1, mid + 1, R);
  A[x] = trans(A[x << 1], A[x << 1 | 1]);
}
matrix query(int x, int l, int r, int L, int R) {
  if (l <= L && R <= r) return A[x];
  int mid = (L + R) / 2;
  if (r <= mid) return query(x << 1, l, r, L, mid);
  if (mid < l) return query(x << 1 | 1, l, r, mid + 1, R);
  return trans(query(x << 1, l, r, L, mid),
               query(x << 1 | 1, l, r, mid + 1, R));
}
int TaskA() {
  int n, q, i, j;
  scanf("%d%d", &n, &q);
  scanf("%s", S + 1);
  build(1, 1, n);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    matrix ans = query(1, l, r, 1, n);
    if (ans.A[0][4] >= INF)
      puts("-1");
    else
      printf("%d\n", ans.A[0][4]);
  }
  return 0;
}
void initialize() {
  int i, j, k;
  for (i = 0; i < 10; i++)
    for (j = 0; j < N; j++)
      for (k = 0; k < N; k++) mat[i].A[j][k] = INF;
  for (i = 0; i < 10; i++)
    for (j = 0; j < N; j++) mat[i].A[j][j] = 0;
  mat[2].A[0][0] = 1;
  mat[2].A[0][1] = 0;
  mat[0].A[1][1] = 1;
  mat[0].A[1][2] = 0;
  mat[1].A[2][2] = 1;
  mat[1].A[2][3] = 0;
  mat[7].A[3][3] = 1;
  mat[7].A[3][4] = 0;
  mat[6].A[3][3] = 1;
  mat[6].A[4][4] = 1;
}
int main() {
  int startTime = clock();
  initialize();
  fprintf(stderr, "/--- initializeTime: %ld milliseconds ---/\n",
          clock() - startTime);
  int T = 1;
  startTime = clock();
  while (T--) TaskA();
  fprintf(stderr, "/--- computeTime: %ld milliseconds ---/\n",
          clock() - startTime);
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

A string t is called nice if a string "2017" occurs in t as a subsequence but a string "2016" doesn't occur in t as a subsequence. For example, strings "203434107" and "9220617" are nice, while strings "20016", "1234" and "20167" aren't nice.

The ugliness of a string is the minimum possible number of characters to remove, in order to obtain a nice string. If it's impossible to make a string nice by removing characters, its ugliness is  - 1.

Limak has a string s of length n, with characters indexed 1 through n. He asks you q queries. In the i-th query you should compute and print the ugliness of a substring (continuous subsequence) of s starting at the index ai and ending at the index bi (inclusive).

Input

The first line of the input contains two integers n and q (4 ≤ n ≤ 200 000, 1 ≤ q ≤ 200 000) — the length of the string s and the number of queries respectively.

The second line contains a string s of length n. Every character is one of digits '0'–'9'.

The i-th of next q lines contains two integers ai and bi (1 ≤ ai ≤ bi ≤ n), describing a substring in the i-th query.

Output

For each query print the ugliness of the given substring.

Examples

Input

8 3
20166766
1 8
1 7
2 8


Output

4
3
-1


Input

15 5
012016662091670
3 4
1 14
4 15
1 13
10 15


Output

-1
2
1
-1
-1


Input

4 2
1234
2 4
1 2


Output

-1
-1

Note

In the first sample:

  * In the first query, ugliness("20166766") = 4 because all four sixes must be removed. 
  * In the second query, ugliness("2016676") = 3 because all three sixes must be removed. 
  * In the third query, ugliness("0166766") = - 1 because it's impossible to remove some digits to get a nice string. 



In the second sample:

  * In the second query, ugliness("01201666209167") = 2. It's optimal to remove the first digit '2' and the last digit '6', what gives a string "010166620917", which is nice. 
  * In the third query, ugliness("016662091670") = 1. It's optimal to remove the last digit '6', what gives a nice string "01666209170". 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 998244353;
const long long maxn = 2e5 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
char S[maxn];
const int N = 5;
struct matrix {
  int A[N][N];
  matrix() { memset(A, 0, sizeof(A)); }
} A[maxn << 2], mat[10];
matrix trans(matrix A, matrix B) {
  matrix C;
  int i, j, k;
  for (i = 0; i < N; i++)
    for (j = 0; j < N; j++) {
      C.A[i][j] = INF;
      for (k = 0; k < N; k++) C.A[i][j] = min(C.A[i][j], A.A[i][k] + B.A[k][j]);
    }
  return C;
}
void build(int x, int L, int R) {
  if (L == R) {
    A[x] = mat[S[L] - '0'];
    return;
  }
  int mid = (L + R) / 2;
  build(x << 1, L, mid);
  build(x << 1 | 1, mid + 1, R);
  A[x] = trans(A[x << 1], A[x << 1 | 1]);
}
matrix query(int x, int l, int r, int L, int R) {
  if (l <= L && R <= r) return A[x];
  int mid = (L + R) / 2;
  if (r <= mid) return query(x << 1, l, r, L, mid);
  if (mid < l) return query(x << 1 | 1, l, r, mid + 1, R);
  return trans(query(x << 1, l, r, L, mid),
               query(x << 1 | 1, l, r, mid + 1, R));
}
int TaskA() {
  int n, q, i, j;
  scanf("%d%d", &n, &q);
  scanf("%s", S + 1);
  build(1, 1, n);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    matrix ans = query(1, l, r, 1, n);
    if (ans.A[0][4] >= INF)
      puts("-1");
    else
      printf("%d\n", ans.A[0][4]);
  }
  return 0;
}
void initialize() {
  int i, j, k;
  for (i = 0; i < 10; i++)
    for (j = 0; j < N; j++)
      for (k = 0; k < N; k++) mat[i].A[j][k] = INF;
  for (i = 0; i < 10; i++)
    for (j = 0; j < N; j++) mat[i].A[j][j] = 0;
  mat[2].A[0][0] = 1;
  mat[2].A[0][1] = 0;
  mat[0].A[1][1] = 1;
  mat[0].A[1][2] = 0;
  mat[1].A[2][2] = 1;
  mat[1].A[2][3] = 0;
  mat[7].A[3][3] = 1;
  mat[7].A[3][4] = 0;
  mat[6].A[3][3] = 1;
  mat[6].A[4][4] = 1;
}
int main() {
  int startTime = clock();
  initialize();
  fprintf(stderr, "/--- initializeTime: %ld milliseconds ---/\n",
          clock() - startTime);
  int T = 1;
  startTime = clock();
  while (T--) TaskA();
  fprintf(stderr, "/--- computeTime: %ld milliseconds ---/\n",
          clock() - startTime);
}

```