#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const long long int maxn = 5010;
long long int n, m;
long long int second[maxn], first[maxn];
long long int cnt[maxn], lt[maxn], rt[maxn];
long long int ltc[maxn], rtc[maxn], lrc[maxn];
vector<pair<long long int, long long int> > typ[maxn];
long long int sz[maxn], ptr[maxn];
pair<long long int, long long int> res[maxn];
void MAIN() {
  cin >> n >> m;
  for (long long int i = (0); i < (n); ++i) cin >> second[i], --second[i];
  for (long long int i = (0); i < (m); ++i) {
    long long int f, h;
    cin >> f >> h, --f;
    typ[f].emplace_back(h, i);
    first[i] = f;
    lt[i] = n, rt[i] = -1;
  }
  for (long long int i = (0); i < (n); ++i)
    sort((typ[i]).begin(), (typ[i]).end()), sz[i] = typ[i].size();
  for (long long int i = (0); i < (n); ++i) {
    long long int c = second[i];
    ++cnt[c];
    if (ptr[c] < sz[c] && typ[c][ptr[c]].first == cnt[c]) {
      lt[typ[c][ptr[c]].second] = i;
      ++ptr[c];
    }
  }
  memset(ptr, 0, sizeof ptr);
  memset(cnt, 0, sizeof cnt);
  for (long long int i = (n)-1; i >= (0); --i) {
    long long int c = second[i];
    ++cnt[c];
    if (ptr[c] < sz[c] && typ[c][ptr[c]].first == cnt[c]) {
      rt[typ[c][ptr[c]].second] = i;
      ++ptr[c];
    }
  }
  lt[m] = -1, rt[m] = -1, first[m] = -1;
  for (long long int i = (0); i < (m + 1); ++i) {
    if (lt[i] == n) continue;
    long long int ct = 0, ctc = 1;
    memset(ltc, 0, sizeof ltc);
    memset(rtc, 0, sizeof rtc);
    memset(lrc, 0, sizeof lrc);
    for (long long int j = (0); j < (m); ++j) {
      if (lt[j] < lt[i] && rt[j] > lt[i]) ++lrc[first[j]];
      if (lt[j] < lt[i]) ++ltc[first[j]];
      if (rt[j] > lt[i]) ++rtc[first[j]];
    }
    for (long long int j = (0); j < (n); ++j) {
      if (first[i] == j) {
        long long int a = rtc[j];
        if (rt[i] > lt[i]) --a;
        if (a > 0) {
          ct += 2;
          ctc = (ctc * (a)) % MOD;
        } else {
          ++ct;
        }
      } else {
        long long int a = ltc[j] * rtc[j] - lrc[j];
        long long int b = ltc[j] + rtc[j];
        if (a) {
          ct += 2;
          ctc = (ctc * (a)) % MOD;
        } else if (b) {
          ++ct;
          ctc = (ctc * (b)) % MOD;
        }
      }
    }
    res[i] = {ct, ctc};
  }
  long long int mx = 0, mxc = 0;
  for (long long int i = (0); i < (m + 1); ++i) mx = max(mx, (res[i].first));
  for (long long int i = (0); i < (m + 1); ++i)
    if (res[i].first == mx) mxc = (mxc + (res[i].second)) % MOD;
  cout << mx << ' ' << mxc << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
3 2
2 3 2
3 1
2 1
    )";
  MAIN();
  return 0;
}
