#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
const long long MOD = 1e9 + 7;
int N, M;
vector<int> pos[MAXN + 10];
vector<pair<int, int> > V[MAXN + 10];
int A[MAXN + 10], B[MAXN + 10], vvv;
int ans[MAXN + 10];
long long twopow[MAXN + 10];
int main() {
  int i, j, k, p;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= N; i++) {
    int t;
    scanf("%d", &t);
    pos[t].push_back(i);
  }
  for (i = 1; i <= M; i++) {
    int f, h;
    scanf("%d%d", &f, &h);
    if (h > pos[f].size()) continue;
    int l = pos[f][h - 1], r = pos[f][pos[f].size() - h];
    V[f].push_back({l, r});
  }
  twopow[0] = 1;
  for (i = 1; i <= N; i++) twopow[i] = twopow[i - 1] * 2 % MOD;
  V[N + 1].push_back({0, 0});
  for (k = 1; k <= N + 1; k++) {
    for (p = 0; p < V[k].size(); p++) {
      int now = V[k][p].first;
      int val = 0;
      long long val2 = 1;
      for (i = 1; i <= N; i++) {
        int a = 0, b = 0, c = 0;
        if (now == 0) b = 0;
        if (k == i) {
          b++;
          for (j = 0; j < V[i].size(); j++) {
            if (j == p) continue;
            pair<int, int> t = V[i][j];
            if (now < t.second) c++;
          }
        } else {
          for (j = 0; j < V[i].size(); j++) {
            pair<int, int> t = V[i][j];
            if (t.first < now && now < t.second)
              a++;
            else if (t.first < now)
              b++;
            else if (now < t.second)
              c++;
          }
        }
        if (a + b != 0 && a + c != 0 && a + b + c >= 2) {
          val += 2;
          long long t = 0;
          t = (t + a * (a - 1)) % MOD;
          t = (t + a * c) % MOD;
          t = (t + a * b) % MOD;
          t = (t + b * c) % MOD;
          val2 = val2 * t % MOD;
        } else if (a + b != 0 || a + c != 0) {
          val += 1;
          long long t = 0;
          if (a + b) t = (t + a + b) % MOD;
          if (a + c) t = (t + a + c) % MOD;
          val2 = val2 * t % MOD;
        }
      }
      ans[val] = (ans[val] + val2) % MOD;
      vvv = max(vvv, val);
    }
  }
  printf("%d %lld\n", vvv, ans[vvv]);
}
