#include <bits/stdc++.h>
using namespace std;
int grass[5555];
vector<pair<int, int>> cows[5555];
int ng, nc;
int maxcow = -1;
long long nocc = 0;
void calc(int maxleft, int next, int seen, long long cur, int curcow) {
  cur %= 1000000007;
  if (next == ng) {
    if (seen) {
      if (curcow > maxcow) maxcow = curcow, nocc = 0;
      if (curcow == maxcow) nocc += cur;
    }
    return;
  }
  int n1 = 0, n2 = 0;
  int mustsee = 0;
  for (int i = 0; i < ((int)cows[next].size()); i++) {
    if (cows[next][i].first < maxleft) n1++;
    if (cows[next][i].first == maxleft) mustsee = 1;
    if (cows[next][i].second > maxleft) n1++;
  }
  if (!mustsee) {
    int nl = 0, nr = 0, nb = 0;
    for (int i = 0; i < ((int)cows[next].size()); i++) {
      int c = 0;
      if (cows[next][i].first < maxleft) nl++, c++;
      if (cows[next][i].second > maxleft) nr++, c++;
      if (c == 2) nb++;
    }
    n2 = nl * nr - nb;
  } else {
    for (int i = 0; i < ((int)cows[next].size()); i++)
      if (cows[next][i].first == maxleft) {
        for (int j = 0; j < ((int)cows[next].size()); j++)
          if (i - j) {
            if (cows[next][j].second > maxleft) {
              n2++;
            }
          }
      }
  }
  if (n2)
    calc(maxleft, next + 1, seen | mustsee, cur * n2, curcow + 2);
  else if (mustsee)
    calc(maxleft, next + 1, 1, cur, curcow + 1);
  else if (n1)
    calc(maxleft, next + 1, seen, cur * n1, curcow + 1);
  else
    calc(maxleft, next + 1, seen, cur, curcow);
}
void doit() {
  scanf("%i%i", &ng, &nc);
  vector<int> grasses[5555];
  for (int i = 0; i < (ng); i++)
    scanf("%i", grass + i), grass[i]--, grasses[grass[i]].push_back(i);
  for (int i = 0; i < (nc); i++) {
    int s, h;
    scanf("%i%i", &s, &h);
    s--;
    if (h <= (int)grasses[s].size()) {
      int cowl = grasses[s][h - 1];
      int cowr = grasses[s][grasses[s].size() - h];
      cows[s].push_back(make_pair(cowl, cowr));
    } else {
      i--;
      nc--;
    }
  }
  for (int i = 0; i < (ng); i++) calc(i, 0, 0, 1, 0);
  calc(-1, 0, 1, 1, 0);
  printf("%i %lli\n", maxcow, nocc % 1000000007);
}
int main() {
  int t = 1;
  while (t--) doit();
}
