#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int64_t inf = 1e9;
const int64_t mod = 1e9 + 7;
void solve() {
  int64_t n, m;
  cin >> n >> m;
  n++;
  int64_t s[n];
  for (int64_t i = 1; i < n; i++) {
    cin >> s[i];
  }
  s[0] = 0;
  int64_t f[m], h[m];
  int64_t L[m], R[m];
  vector<pair<int64_t, int64_t>> cows[n];
  cows[0] = {{0, 0}};
  for (int64_t i = 0; i < m; i++) {
    cin >> f[i] >> h[i];
    if (count(s, s + n, f[i]) < h[i]) {
      L[i] = R[i] = -1;
    } else {
      L[i] = 0;
      int64_t cnt = 0;
      while (cnt < h[i]) {
        cnt += s[L[i]] == f[i];
        L[i]++;
      }
      cnt = 0;
      R[i] = n - 1;
      while (cnt < h[i]) {
        cnt += s[R[i]] == f[i];
        R[i]--;
      }
      L[i]--, R[i]++;
    }
    if (L[i] != -1) {
      cows[f[i]].push_back({L[i], R[i]});
    }
  }
  int64_t ans = 1;
  int64_t mx = 0;
  for (int64_t i = 0; i < n; i++) {
    int64_t dp[n + 1], cr[n + 1];
    memset(dp, 0, sizeof(dp));
    memset(cr, 0, sizeof(cr));
    dp[0] = 1;
    bool ok = false;
    for (int64_t j = 0; j < n; j++) {
      int64_t cnt[3][2];
      memset(cnt, 0, sizeof(cnt));
      for (auto it : cows[j]) {
        int64_t A = it.first > i ? 0 : it.first < i ? 1 : 2;
        int64_t B = it.second > i;
        cnt[A][B]++;
      }
      if (cnt[2][0] || cnt[2][1]) {
        if (cnt[1][1] || cnt[0][1]) {
          cr[j + 1] = cr[j] + 2;
          dp[j + 1] = dp[j] * (cnt[1][1] + cnt[0][1]) % mod;
        } else {
          cr[j + 1] = cr[j] + 1;
          dp[j + 1] = dp[j];
        }
        ok = true;
      } else if (cnt[1][1] >= 2 || (cnt[1][0] && cnt[0][1]) ||
                 (cnt[1][1] && (cnt[0][1] || cnt[1][0]))) {
        cr[j + 1] = cr[j] + 2;
        dp[j + 1] =
            dp[j] *
            ((cnt[1][1] * (cnt[1][1] - 1) % mod + cnt[1][0] * cnt[0][1] % mod +
              cnt[1][1] * (cnt[0][1] + cnt[1][0]) % mod) %
             mod) %
            mod;
      } else if (cnt[1][0] || cnt[0][1] || cnt[1][1]) {
        cr[j + 1] = cr[j] + 1;
        dp[j + 1] = dp[j] * (cnt[1][0] + cnt[0][1] + 2 * cnt[1][1]) % mod;
      } else {
        cr[j + 1] = cr[j];
        dp[j + 1] = dp[j];
      }
    }
    if (!ok) {
      continue;
    }
    if (cr[n] > mx) {
      mx = cr[n];
      ans = dp[n];
    } else if (cr[n] == mx) {
      ans = (ans + dp[n]) % mod;
    }
  }
  cout << mx - 1 << ' ' << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int64_t t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
