#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 5000 + 5;
int lefts[maxn], rights[maxn], num[maxn], ways[maxn], s[maxn];
int n, m;
vector<int> v[maxn];
void solve1(int id) {
  int a = upper_bound(v[id].begin(), v[id].end(), rights[id]) - v[id].begin();
  int b = upper_bound(v[id].begin(), v[id].end(), lefts[id]) - v[id].begin();
  long long cnt2 = a * b - min(a, b);
  long long cnt1 = a + b;
  if (cnt2 > 0) {
    ways[id] = cnt2;
    num[id] = 2;
  } else if (cnt1 > 0) {
    ways[id] = cnt1;
    num[id] = 1;
  } else {
    ways[id] = 1;
    num[id] = 0;
  }
}
long long ans_tot = -1, ans_ways = 1;
long long add(long long a, long long b) {
  a = (a + mod) % mod, b = (b + mod) % mod;
  return (a + b + mod) % mod;
}
void update(long long tmp_tot, long long tmp_ways) {
  if (tmp_tot > ans_tot) {
    ans_tot = tmp_tot;
    ans_ways = tmp_ways;
  } else if (tmp_tot == ans_tot) {
    ans_ways = add(ans_ways, tmp_ways);
  }
}
void solve2(int id) {
  int a = upper_bound(v[id].begin(), v[id].end(), rights[id]) - v[id].begin();
  if (rights[id] >= lefts[id]) a--;
  if (a > 0) {
    ways[id] = a;
    num[id] = 2;
  } else {
    ways[id] = 1;
    num[id] = 1;
  }
}
long long mul(long long a, long long b) {
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a % mod) * (b % mod) % mod;
}
long long fpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
long long inv(long long x) { return fpow(x, mod - 2); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]), rights[s[i]]++;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
  }
  for (int i = 1; i <= m; i++) sort(v[i].begin(), v[i].end());
  for (int i = 1; i <= n; i++) {
    solve1(i);
  }
  long long tmp_tot = 0, tmp_ways = 1;
  for (int i = 1; i <= n; i++) {
    tmp_tot += num[i];
    tmp_ways = mul(tmp_ways, ways[i]);
  }
  update(tmp_tot, tmp_ways);
  for (int i = 1; i <= n; i++) {
    tmp_tot -= num[s[i]];
    tmp_ways = mul(tmp_ways, inv(ways[s[i]]));
    rights[s[i]]--, lefts[s[i]]++;
    if (binary_search(v[s[i]].begin(), v[s[i]].end(), lefts[s[i]])) {
      solve2(s[i]);
      update(tmp_tot + num[s[i]], mul(tmp_ways, ways[s[i]]));
    }
    solve1(s[i]);
    tmp_tot += num[s[i]];
    tmp_ways = mul(tmp_ways, ways[s[i]]);
  }
  printf("%lld %lld\n", ans_tot, ans_ways);
  return 0;
}
