#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const long long int MOD64 = (long long int)(1e18) + 7;
const int INF = 0x7fffffff;
const long long int INF64 = 0x7fffffffffffffff;
const int N = 5000 + 10;
int a[N], lnum[N], rnum[N];
int n, m;
vector<int> H[N];
long long int cal(int x, int val) {
  int l = 0, r = H[x].size() - 1, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (H[x][mid] <= val) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans + 1;
}
pair<int, long long int> solve() {
  int ans = 0;
  long long int num = 1;
  for (int i = int(1); i < int(n + 1); i++) {
    long long int tmp = 0;
    tmp = cal(i, lnum[i]) * cal(i, rnum[i]) - cal(i, min(lnum[i], rnum[i]));
    if (tmp > 0) {
      ans += 2;
      num = (num * tmp) % MOD;
      continue;
    }
    tmp = cal(i, lnum[i]) + cal(i, rnum[i]);
    if (tmp != 0) {
      ans += 1;
      num = (num * tmp) % MOD;
    }
  }
  return {ans, num};
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = int(1); i < int(n + 1); i++) {
    cin >> a[i];
    rnum[a[i]]++;
  }
  for (int i = int(0); i < int(m); i++) {
    int f, h;
    cin >> f >> h;
    H[f].push_back(h);
  }
  for (int i = int(1); i < int(n + 1); i++) sort((H[i]).begin(), (H[i]).end());
  int ans = 0;
  long long int num = 0;
  for (int i = int(0); i < int(n + 1); i++) {
    rnum[a[i]]--;
    lnum[a[i]]++;
    pair<int, long long int> tmp = solve();
    if (ans < tmp.first) {
      ans = tmp.first;
      num = tmp.second;
    } else if (ans == tmp.first) {
      num = (num + tmp.second) % MOD;
    }
  }
  memset(lnum, 0, sizeof(lnum));
  memset(rnum, 0, sizeof(rnum));
  for (int i = int(1); i < int(n + 1); i++) rnum[a[i]]++;
  for (int i = int(0); i < int(n); i++) {
    rnum[a[i + 1]]--;
    lnum[a[i]]++;
    pair<int, long long int> tmp = solve();
    if (tmp.first == ans) num = (num - tmp.second + MOD) % MOD;
  }
  cout << ans << ' ' << num << endl;
  return 0;
}
