#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, a[N];
long long suml[N], sumr[N], num[N][N], mod = 1e9 + 7;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sumr[a[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = y; j <= n; j++) num[x][j]++;
  }
  pair<long long, long long> ans = make_pair(0, 0);
  for (int i = 0; i <= n; i++) {
    if (i) suml[a[i]]++, sumr[a[i]]--;
    int x = a[i];
    long long l = suml[x], r = sumr[x];
    pair<long long, long long> t = make_pair(0, 1);
    if (i) {
      long long cnt1 = num[x][l] - num[x][l - 1], cnt2 = num[x][r] - (l <= r);
      if (!cnt1) continue;
      t.first++, t.second = t.second * cnt1 % mod;
      if (cnt2) t.first++, t.second = t.second * cnt2 % mod;
    }
    for (int y = 1; y <= n; y++)
      if (y != x) {
        long long cnt1 = num[y][suml[y]], cnt2 = num[y][sumr[y]];
        if (cnt1 > cnt2) swap(cnt1, cnt2);
        if (cnt2) {
          t.first++;
          if (!cnt1)
            t.second = t.second * cnt2 % mod;
          else if (cnt2 == 1)
            t.second = 2LL * t.second % mod;
          else
            t.first++, t.second = t.second * cnt1 * (cnt2 - 1) % mod;
        }
      }
    if (t.first > ans.first)
      ans = t;
    else if (t.first == ans.first)
      ans.second = (ans.second + t.second) % mod;
  }
  printf("%lld %lld", ans.first, ans.second);
  return 0;
}
