#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
  if (x < y) x = y;
}
void chmin(int &x, int y) {
  if (x > y) x = y;
}
int n, m, c[5005], num[5005], len[5005], num2[5005], cl[5005], cr[5005];
pair<int, int> ff[5005];
bool ok[5005], ok2[5005], val[5005];
pair<int, int> cow[5005];
vector<int> color[5005];
pair<int, int> Ans;
void upd(pair<int, int> &a, pair<int, int> b) {
  a = make_pair(a.first + b.first, (int)((long long)a.second * b.second % mod));
}
pair<int, int> deal(int cut) {
  if (cut)
    for (int(i) = (1); (i) <= (n); (i)++) cl[i] += (ok[cut] && c[cut] == i);
  if (cut)
    for (int(i) = (1); (i) <= (n); (i)++) cr[i] -= (ok2[cut] && c[cut] == i);
  for (int(i) = (1); (i) <= (n); (i)++) num[i] = num2[i] = val[i] = 0;
  if (cut != 0 && !ok[cut]) {
    return make_pair(-1, -1);
  }
  int vc = c[cut];
  pair<int, int> ans;
  ans.first = 0;
  ans.second = 1;
  for (int(i) = (1); (i) <= (n); (i)++)
    if (ok[i]) {
      pair<int, int> a = ff[i];
      int to = color[a.first][len[a.first] - a.second - 1];
      if (to > cut)
        num[c[i]]++, val[i] = 1;
      else
        val[i] = 0;
    }
  for (int(i) = (1); (i) <= (cut); (i)++)
    if (ok[i]) {
      if (c[i] == vc) {
        if (i == cut) num2[c[i]] += num[c[i]] - val[i];
      } else {
        num2[c[i]] += num[c[i]] - val[i];
      }
    }
  for (int(col) = (1); (col) <= (n); (col)++) {
    if (num2[col] == 0) {
      if (cl[col] + cr[col] == 0)
        upd(ans, make_pair(0, 1));
      else {
        if (col == vc)
          upd(ans, make_pair(1, 1));
        else
          upd(ans, make_pair(1, cl[col] + cr[col]));
      }
    } else {
      upd(ans, make_pair(2, num2[col]));
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", c + i);
  for (int(i) = (1); (i) <= (m); (i)++)
    scanf("%d%d", &cow[i].first, &cow[i].second), cow[i].second--;
  for (int(i) = (1); (i) <= (n); (i)++) {
    color[c[i]].push_back(i);
    len[c[i]]++;
    ff[i] = make_pair(c[i], len[c[i]] - 1);
  }
  for (int(i) = (1); (i) <= (m); (i)++) {
    if (color[cow[i].first].size() <= cow[i].second) continue;
    ok[color[cow[i].first][cow[i].second]] = 1;
    ok2[color[cow[i].first][len[cow[i].first] - cow[i].second - 1]] = 1;
  }
  Ans.second = 1;
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (1); (j) <= (n); (j)++) cr[i] += (ok2[j] && c[j] == i);
  for (int(i) = (0); (i) <= (n); (i)++) {
    pair<int, int> res = deal(i);
    if (Ans.first < res.first) {
      Ans = res;
    } else if (Ans.first == res.first) {
      Ans.second = (Ans.second + res.second) % mod;
    }
  }
  if (Ans.first == 0) Ans.second = 1;
  printf("%d %d\n", Ans.first, Ans.second);
  return 0;
}
