#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const int Mod = 1000000007;
long long R() {
  long long ans = 0, f = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 + c - '0';
  return ans * f;
}
int n, m, tp[N], Del, fx;
int c[N], d1[N], d2[N];
long long Pow(long long x, long long bs) {
  long long an = 1;
  for (; bs; bs >>= 1, x = x * x % Mod)
    if (bs & 1) an = an * x % Mod;
  return an;
}
long long Ni(long long x) { return Pow(x, Mod - 2); }
struct Num {
  long long an, fn;
} ans, a2;
void Add(Num &a, Num b) {
  if (a.an > b.an) return;
  if (a.an == b.an) {
    a.fn += b.fn;
    a.fn %= Mod;
    return;
  }
  a = b;
}
vector<int> v[N];
int ckr(int col, int fj) {
  int an = 0;
  for (auto i : v[col])
    if (i != Del) {
      if (d2[i] <= fj) break;
      ++an;
    }
  return an;
}
int ckl(int col, int fj) {
  int an = 0;
  for (auto i : v[col])
    if (i != Del) {
      if (d1[i] >= fj) break;
      ++an;
    }
  return an;
}
int ck2(int col, int fj) {
  int p1 = 0, p2 = 0;
  long long fn = 0;
  for (auto i : v[col])
    if (i != Del) {
      int f1 = d1[i] < fj;
      int f2 = d2[i] > fj;
      if (f1 == f2 && f1 == 1) --fn;
      p1 += f1;
      p2 += f2;
    }
  fn += p1 * p2;
  fn %= Mod;
  return fn;
}
int aa1, aa2;
Num Sol3(int col, int fj) {
  if (c[Del] == col) {
    long long fn = 0;
    if (fx == 1)
      fn = ckr(col, fj);
    else
      fn = ckl(col, fj);
    if (fn == 0) return (Num){1, 1};
    return (Num){2, fn};
  }
  int fn = ck2(col, fj);
  if (fn) return (Num){2, fn};
  fn += aa1 = ckr(col, fj);
  fn += aa2 = ckl(col, fj);
  if (fn == 0) return (Num){0, 1};
  return (Num){1, fn};
}
Num Sol4(int col, int fj) {
  if (c[Del] == col) {
    return (Num){1, 1};
  }
  int fn = 0;
  if (fx == 2) fn += aa1;
  if (fx == 1) fn += aa2;
  if (fn == 0) return (Num){0, 1};
  return (Num){1, fn};
}
void Sol2(int fj) {
  Num an = (Num){0, 1}, aa = (Num){0, 1};
  for (int i = 1; i <= n; ++i) {
    Num a = Sol3(i, fj);
    an.an += a.an;
    an.fn *= a.fn;
    an.fn %= Mod;
  }
  Add(ans, an);
}
void Sol(int x) {
  if (d1[x] > n) return;
  Del = x;
  fx = 1;
  Sol2(d1[x]);
}
bool cmp(int x, int y) { return d1[x] < d1[y]; }
int main() {
  n = R();
  m = R();
  for (int i = 1; i <= n; ++i) tp[i] = R();
  for (int i = 1; i <= m; ++i) {
    c[i] = R();
    int x = R();
    int u = x;
    d1[i] = n + 1;
    d2[i] = -1;
    for (int j = 1; j <= n; ++j) {
      if (tp[j] == c[i]) --u;
      if (u == 0) {
        d1[i] = j;
        break;
      }
    }
    u = x;
    for (int j = n; j >= 1; --j) {
      if (tp[j] == c[i]) --u;
      if (u == 0) {
        d2[i] = j;
        break;
      }
    }
  }
  ans.fn = 1;
  for (int i = 1; i <= m; ++i) v[c[i]].push_back(i);
  for (int i = 1; i <= n; ++i) sort(v[i].begin(), v[i].end(), cmp);
  for (int i = 0; i <= m; ++i) Sol(i);
  ans.fn %= Mod;
  ans.fn += Mod;
  ans.fn %= Mod;
  if (ans.an == 0) ans.fn = 1;
  cout << ans.an << ' ' << ans.fn;
  return 0;
}
