#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 5000 + 5;
const int mod = 1000000007;
int n, m;
int s[maxn];
int f[maxn], h[maxn];
map<pair<int, int>, int> cows;
int l[maxn], r[maxn];
int pre[maxn], suf[maxn];
int cnt[maxn][4];
void sweep() {
  for (int i = (1); i <= (n); ++i) {
    auto it = cows.find(pair<int, int>(s[i], ++pre[s[i]]));
    if (it != cows.end()) l[it->second] = i;
  }
  for (int i = n; i >= 1; --i) {
    auto it = cows.find(pair<int, int>(s[i], ++suf[s[i]]));
    if (it != cows.end()) r[it->second] = i;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i) scanf("%d", &s[i]);
  for (int i = 0; i < (m); ++i) {
    scanf("%d%d", &f[i], &h[i]);
    cows[pair<int, int>(f[i], h[i])] = i;
    l[i] = inf, r[i] = -inf;
  }
  sweep();
  int X = 0, Y = 1;
  for (int i = 0; i < (m); ++i)
    if (r[i] > 0) ++cnt[f[i]][2];
  for (int t = (1); t <= (n); ++t)
    if (cnt[t][2]) ++X, Y = (long long)Y * cnt[t][2] % mod;
  for (int i = 0; i < (m); ++i)
    if (l[i] <= n) {
      int x = 1, y = 1;
      memset(cnt, 0, sizeof(cnt));
      for (int j = 0; j < (m); ++j)
        if (j != i) {
          int mask = 0;
          if (f[j] != f[i] && l[j] < l[i]) mask |= 1;
          if (r[j] > l[i]) mask |= 2;
          ++cnt[f[j]][mask];
        }
      for (int t = (1); t <= (n); ++t) {
        int c = ((cnt[t][1] + cnt[t][3]) * (cnt[t][2] + cnt[t][3]) - cnt[t][3]);
        if (c) {
          x += 2, y = (long long)y * c % mod;
          continue;
        }
        c = cnt[t][1] + cnt[t][2] + cnt[t][3] * 2;
        if (c) ++x, y = (long long)y * c % mod;
      }
      if (x > X)
        X = x, Y = y;
      else if (x == X)
        Y = (Y + y) % mod;
    }
  printf("%d %d\n", X, Y);
  return 0;
}
