#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<int> F[N];
int s[N];
int L[N], R[N];
int f[N], h[N];
int just_R[N];
int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> f[i] >> h[i];
    F[f[i]].push_back(i);
    int ate = 0, l_stop = n + 1;
    for (int j = 1; j <= n; j++) {
      if (s[j] == f[i]) {
        ate++;
        if (ate == h[i]) {
          l_stop = j;
          break;
        }
      }
    }
    L[i] = l_stop;
    ate = 0;
    int r_stop = 0;
    for (int j = n; j >= 1; j--) {
      if (s[j] == f[i]) {
        ate++;
        if (ate == h[i]) {
          r_stop = j;
          break;
        }
      }
    }
    R[i] = r_stop;
    if (r_stop > 0) just_R[f[i]]++;
  }
  int ways = 1, best = 0;
  for (int i = 1; i <= n; i++) {
    best += (just_R[i] > 0);
    if (just_R[i] > 0) ways = 1ll * ways * just_R[i] % mod;
  }
  for (int i = 1; i <= m; i++) {
    if (L[i] > n) continue;
    int cur = 1;
    int cur_ways = 1;
    int mid = L[i];
    for (int fav = 1; fav <= n; fav++) {
      int both = 0, lft_only = 0, rgt_only = 0;
      for (int idx : F[fav]) {
        if (idx == i) continue;
        if (L[idx] < mid && R[idx] > mid)
          both++;
        else if (L[idx] < mid)
          lft_only++;
        else if (R[idx] > mid)
          rgt_only++;
      }
      if (fav == f[i]) {
        if (rgt_only + both > 0) {
          cur++;
          cur_ways = 1ll * cur_ways * (rgt_only + both) % mod;
        }
      } else {
        int x = 0;
        if (both >= 2)
          x += 2;
        else if (both == 1 && (lft_only > 0 or rgt_only > 0))
          x += 2;
        else if (both == 1)
          x++;
        else
          x += (lft_only > 0) + (rgt_only > 0);
        cur += x;
        int cnt = 0;
        if (x == 2) {
          cnt += 1ll * lft_only * both % mod;
          cnt %= mod;
          cnt += 1ll * lft_only * rgt_only % mod;
          cnt %= mod;
          cnt += 1ll * both * (both - 1) % mod;
          cnt %= mod;
          cnt += 1ll * both * rgt_only % mod;
          cnt %= mod;
        } else if (x == 1) {
          cnt = 2 * both + lft_only + rgt_only;
        } else
          cnt = 1;
        cur_ways = 1ll * cur_ways * cnt % mod;
      }
    }
    if (best < cur) {
      best = cur;
      ways = cur_ways;
    } else if (best == cur) {
      ways += cur_ways;
      ways %= mod;
    }
  }
  cout << best << " " << ways << endl;
  return 0;
}
