#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
using LL = int_fast64_t;
const int MAXN = 5555;
const LL MOD = 1e9 + 7;
int n, m, A[MAXN], l[MAXN], r[MAXN];
vector<int> cow[MAXN];
pair<int, LL> gao() {
  int cows = 0;
  LL ways = 1;
  for (int i = 1; i <= n; i++) {
    int pa = upper_bound(cow[i].begin(), cow[i].end(), l[i]) - cow[i].begin();
    int pb = upper_bound(cow[i].begin(), cow[i].end(), r[i]) - cow[i].begin();
    if (pa * pb - min(pa, pb) > 0) {
      cows += 2;
      ways = ways * (pa * pb - min(pa, pb)) % MOD;
    } else if (pa || pb) {
      cows += 1;
      ways = ways * (pa + pb) % MOD;
    }
  }
  return make_pair(cows, ways);
}
int main() {
  ____();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    r[A[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    int f, h;
    cin >> f >> h;
    cow[f].emplace_back(h);
  }
  for (int i = 1; i <= n; i++) sort(cow[i].begin(), cow[i].end());
  int sleepcow = 0;
  LL ways = 0;
  for (int i = 0; i <= n; i++) {
    r[A[i]]--;
    l[A[i]]++;
    auto p = gao();
    if (p.first < sleepcow)
      continue;
    else if (p.first == sleepcow)
      ways = (ways + p.second) % MOD;
    else {
      sleepcow = p.first;
      ways = p.second;
    }
  }
  memset(l, 0, sizeof(l));
  for (int i = 1; i <= n; i++) r[A[i]]++;
  LL over = 0;
  for (int i = 1; i <= n; i++) {
    r[A[i]]--;
    auto p = gao();
    if (p.first == sleepcow) over = (over + p.second) % MOD;
    l[A[i]]++;
  }
  cout << sleepcow << ' ' << (ways - over + MOD) % MOD << endl;
  return 0;
}
