#include <bits/stdc++.h>
using namespace std;
const int MX = 5005, mod = 1000000007;
int n, m, a[MX], f[MX], h[MX];
int mx;
long long cn = 1;
vector<int> pos[MX], v[MX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> f[i] >> h[i];
    v[f[i]].push_back(h[i]);
  }
  for (int i = 1; i <= n; i++) {
    int f = 0;
    for (int x : v[i])
      if (x <= pos[i].size()) f++;
    if (f) {
      mx++;
      (cn *= f) %= mod;
    }
  }
  for (int i = 0; i < n; i++) {
    int can = 0, f = 0;
    long long acu = 1;
    for (int j = 1; j <= n; j++) {
      int a = 0, b = 0, ab = 0, g = 0;
      for (int x : v[j])
        if (x <= pos[j].size()) {
          int fa = 0, fb = 0;
          if (pos[j][x - 1] < i) fa = 1;
          if (*(pos[j].end() - x) > i) fb = 1;
          if (pos[j][x - 1] == i) {
            g = 1;
            fb = 0;
          }
          a += fa;
          b += fb;
          ab += fa & fb;
        }
      if (g) {
        a = 1, ab = 0, f = 1;
      }
      if (a * b - ab) {
        can += 2;
        (acu *= a * b - ab) %= mod;
      } else if (a + b) {
        can++;
        (acu *= a + b) %= mod;
      }
    }
    if (f) {
      if (can > mx) {
        mx = can;
        cn = acu;
      } else if (can == mx) {
        (cn += acu) %= mod;
      }
    }
  }
  cout << mx << " " << cn << '\n';
  return 0;
}
