#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c ^ '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
const long long mod = 1000000007;
long long mo(long long a) { return a >= mod ? a - mod : a; }
const int maxn = 5005;
int n, m, num[maxn][maxn], slm[maxn], srm[maxn], s[maxn];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) ++srm[s[i] = read()];
  for (int i = 1, f, h; i <= m; ++i) {
    f = read();
    h = read();
    ++num[f][h];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) num[i][j] += num[i][j - 1];
  long long anssum = 1, ansnum = 0;
  for (int i = 0; i <= n; ++i) {
    if (i) ++slm[s[i]], --srm[s[i]];
    long long testsum = 1, testnum = 0;
    int sl, sr;
    if (i) {
      sl = slm[s[i]], sr = srm[s[i]];
      sr = num[s[i]][sr] - (sr >= sl);
      sl = num[s[i]][sl] - num[s[i]][sl - 1];
      if (!sl) continue;
      if (sr)
        testsum = testsum * sl * sr % mod, testnum += 2;
      else
        testsum = testsum * sl % mod, testnum++;
    }
    for (int j = 1; j <= n; ++j) {
      if (j == s[i]) continue;
      sl = slm[j], sr = srm[j];
      sr = num[j][sr], sl = num[j][sl];
      if (!sl && !sr) continue;
      if (!sl || !sr)
        testsum = testsum * (sl + sr) % mod, testnum++;
      else if (sr == 1 && sl == 1)
        testsum = testsum * 2 % mod, testnum++;
      else
        testsum = testsum * (sl * sr - min(sl, sr)) % mod, testnum += 2;
    }
    if (testnum > ansnum)
      ansnum = testnum, anssum = testsum;
    else if (testnum == ansnum)
      anssum = mo(anssum + testsum) % mod;
  }
  if (!ansnum) {
    cout << "0 1\n";
    return 0;
  }
  cout << ansnum << " " << anssum << "\n";
  return 0;
}
