#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void add(long long &a, long long b) { a = (a + b) % mod; };
void mul(long long &a, long long b) { a = (a * b) % mod; }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> sweetness_indices(n);
  vector<int> grass(n);
  for (int i = 0; i < n; ++i) {
    cin >> grass[i];
    sweetness_indices[--grass[i]].push_back(i);
  }
  for (auto &i : sweetness_indices) sort(i.begin(), i.end());
  vector<vector<int>> cows(n);
  while (m--) {
    int f, h;
    cin >> f >> h;
    cows[--f].push_back(h);
  }
  for (auto &i : cows) sort(i.begin(), i.end());
  int max_cows = 0;
  long long num_ways = 0;
  for (int i = -1; i < n; ++i) {
    int cows_satisfied = 0;
    long long ways = 1;
    bool fail = false;
    for (int s = 0; s < cows.size(); ++s) {
      int n_grass = sweetness_indices[s].size();
      if (i != -1 && s == grass[i]) {
        int need_cnt = lower_bound(sweetness_indices[s].begin(),
                                   sweetness_indices[s].end(), i) -
                       sweetness_indices[s].begin() + 1;
        long long works_left = 0;
        long long works_right = 0;
        for (auto cnt : cows[s]) {
          if (cnt == need_cnt && works_left == 0) {
            ++works_left;
            continue;
          }
          if (cnt > n_grass)
            continue;
          else if (sweetness_indices[s][n_grass - cnt] > i)
            ++works_right;
        }
        if (works_left) {
          if (works_right) {
            cows_satisfied += 2;
            mul(ways, works_right);
          } else {
            ++cows_satisfied;
          }
        } else {
          fail = true;
        }
        continue;
      }
      long long works_left = 0;
      long long works_right = 0;
      long long works_both = 0;
      for (auto cnt : cows[s]) {
        if (cnt > n_grass) continue;
        if (sweetness_indices[s][cnt - 1] <= i &&
            sweetness_indices[s][n_grass - cnt] > i)
          ++works_both;
        else if (sweetness_indices[s][cnt - 1] <= i)
          ++works_left;
        else if (sweetness_indices[s][n_grass - cnt] > i)
          ++works_right;
      }
      long long works_one = works_left ^ works_right;
      if (works_both > 1 || (works_one > 0 && works_both > 0)) {
        cows_satisfied += 2;
        mul(ways, (works_both * works_one) + (works_both - 1) * (works_both));
      } else if (works_both == 1) {
        ++cows_satisfied;
        mul(ways, 2);
      } else if (works_one) {
        ++cows_satisfied;
        mul(ways, works_one);
      }
    }
    if (fail) continue;
    if (cows_satisfied > max_cows) {
      max_cows = cows_satisfied;
      num_ways = ways;
    } else if (cows_satisfied == max_cows) {
      add(num_ways, ways);
    }
  }
  if (max_cows == 0) {
    cout << "0 1" << endl;
    return 0;
  }
  cout << max_cows << " " << num_ways << endl;
}
