#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m;
int s[5055];
struct Node {
  int f, h;
  bool operator<(const Node &a) const {
    return f < a.f || (f == a.f && (h < a.h));
  }
} a[5055];
vector<int> A[5055], B[5055];
int lp[5055], rp[5055];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    A[s[i]].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    a[i] = (Node){u, v};
  }
  sort(a + 1, a + m + 1);
  for (int i = 1; i <= m;) {
    int j = i;
    while (j <= m && a[j].f == a[i].f) j++;
    while (i < j) {
      if (a[i].h <= A[a[i].f].size()) B[a[i].f].push_back(a[i].h);
      i++;
    }
  }
  int ans = 0;
  long long cc = 1;
  for (int i = 1; i <= n; i++) lp[i] = 0, rp[i] = B[i].size() - 1;
  for (int split = 0; split <= n; split++) {
    int tot = 0;
    long long ct = 1;
    for (int i = 1; i <= n; i++)
      if (A[i].size() && B[i].size()) {
        while (lp[i] < B[i].size() && A[i][B[i][lp[i]] - 1] <= split) lp[i]++;
        while (rp[i] >= 0 && A[i][A[i].size() - B[i][rp[i]]] <= split) rp[i]--;
        int lans = lp[i], rans = rp[i] + 1;
        if (lans * rans - min(lans, rans)) {
          tot += 2;
          (ct *= lans * rans - min(lans, rans)) %= MOD;
        } else if (lans + rans) {
          tot += 1;
          (ct *= lans + rans) %= MOD;
        }
      }
    if (tot > ans)
      ans = tot, cc = ct;
    else if (tot == ans) {
      (cc += ct) %= MOD;
    }
  }
  for (int i = 1; i <= n; i++) lp[i] = 0, rp[i] = B[i].size() - 1;
  for (int split = 1; split <= n; split++) {
    int tot = 0;
    long long ct = 1;
    for (int i = 1; i <= n; i++)
      if (A[i].size() && B[i].size()) {
        while (lp[i] < B[i].size() && A[i][B[i][lp[i]] - 1] <= split - 1)
          lp[i]++;
        while (rp[i] >= 0 && A[i][A[i].size() - B[i][rp[i]]] <= split) rp[i]--;
        int lans = lp[i], rans = rp[i] + 1;
        if (lans * rans - min(lans, rans)) {
          tot += 2;
          (ct *= lans * rans - min(lans, rans)) %= MOD;
        } else if (lans + rans) {
          tot += 1;
          (ct *= lans + rans) %= MOD;
        }
      }
    if (tot == ans) {
      (cc -= ct) %= MOD;
    }
  }
  cc = (cc + MOD) % MOD;
  cout << ans << " " << (ans == 0 ? 1ll : cc) << endl;
}
