#include <bits/stdc++.h>
using namespace std;
int a[5007];
vector<int> v[5007];
int l[5007], r[5007];
const long long mod = 1e9 + 7;
int n, m;
int binary_search_(int color, int num) {
  int point =
      upper_bound(v[color].begin(), v[color].end(), num) - v[color].begin();
  return point;
}
pair<int, long long> solve() {
  long long sum = 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = binary_search_(i, l[i]);
    int y = binary_search_(i, r[i]);
    if (x * y - min(x, y) > 0) {
      ans += 2;
      sum = (sum * (x * y - min(x, y))) % mod;
    } else if (x || y) {
      ++ans;
      sum = (sum * (x + y)) % mod;
    }
  }
  return make_pair(ans, sum);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ++r[a[i]];
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
  int ans = 0;
  long long num = 0;
  for (int i = 0; i <= n; i++) {
    --r[a[i]];
    ++l[a[i]];
    pair<int, long long> pr = solve();
    if (pr.first > ans) {
      ans = pr.first;
      num = pr.second;
    } else if (pr.first == ans)
      num = (num + pr.second) % mod;
  }
  for (int i = 0; i <= n; i++) {
    l[a[i]] = 0;
    ++r[a[i]];
  }
  for (int i = 0; i < n; i++) {
    --r[a[i + 1]];
    ++l[a[i]];
    pair<int, long long> pr = solve();
    if (pr.first == ans) num = (mod + num - pr.second) % mod;
  }
  cout << ans << " " << num << endl;
  return 0;
}
