#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int a[5010];
vector<int> grass[5010], cow[5010], l;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    grass[a[i]].emplace_back(i);
  }
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (y > grass[x].size()) continue;
    cow[x].emplace_back(y);
    l.emplace_back(grass[x][y - 1]);
  }
  for (int i = 1; i <= n; i++) sort(cow[i].begin(), cow[i].end());
  a[0] = -1;
  l.emplace_back(0);
  sort(l.begin(), l.end());
  long long ans = -1, sum = 0;
  for (auto cur : l) {
    long long num = 1, cnt = 1;
    if (cur == 0) num = 0;
    for (int i = 1; i <= n; i++)
      if (i == a[cur]) {
        int x = upper_bound(grass[i].begin(), grass[i].end(), cur) -
                grass[i].begin();
        int y = grass[i].size() - x;
        int cow_x =
            upper_bound(cow[i].begin(), cow[i].end(), x) - cow[i].begin();
        int cow_y =
            upper_bound(cow[i].begin(), cow[i].end(), y) - cow[i].begin();
        if (cow_y) {
          num++;
          if (cow_x <= cow_y) {
            if (cow_y > 1)
              cnt = cnt * (long long)(cow_y - 1) % MOD;
            else
              num--;
          } else
            cnt = cnt * (long long)cow_y % MOD;
        }
      } else {
        int x = upper_bound(grass[i].begin(), grass[i].end(), cur) -
                grass[i].begin();
        int y = grass[i].size() - x;
        int cow_x =
            upper_bound(cow[i].begin(), cow[i].end(), x) - cow[i].begin();
        int cow_y =
            upper_bound(cow[i].begin(), cow[i].end(), y) - cow[i].begin();
        if (cow_x <= 0 && cow_y <= 0) continue;
        if (cow_x <= 0 || cow_y <= 0) {
          num++;
          cnt = cnt * (long long)max(cow_x, cow_y) % MOD;
        } else {
          if (cow_x == 1 && cow_y == 1) {
            num++;
            cnt = cnt * 2LL % MOD;
          } else {
            num += 2;
            cnt = cnt *
                  ((long long)cow_x * (long long)cow_y - min(cow_x, cow_y)) %
                  MOD;
          }
        }
      }
    if (num > ans) {
      ans = num;
      sum = cnt;
    } else if (num == ans)
      sum = (sum + cnt) % MOD;
  }
  printf("%lld %lld\n", ans, sum);
}
