#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200009;
const long long MOD = 1e9 + 7;
class {
 public:
  void solve() {
    int n, m;
    cin >> n >> m;
    vector<long long> A(n + 2), C(n + 2), PC(n + 2);
    for (int i = 1; i <= n; ++i) cin >> A[i], C[A[i]]++;
    vector<vector<long long>> B(n + 2, vector<long long>(n + 2));
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      B[a][b] = 1;
    }
    long long ans = 0, count = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) B[i][j] += B[i][j - 1];
      if (C[i] && B[i][C[i]]) {
        ans++;
        count = (count * B[i][C[i]]) % MOD;
      }
    }
    for (int i = 1; i <= n; ++i) {
      long long curans = 0, curcount = 1;
      C[A[i]]--;
      PC[A[i]]++;
      if (B[A[i]][PC[A[i]]] == B[A[i]][PC[A[i]] - 1]) continue;
      for (int j = 1; j <= n; ++j) {
        if (j == A[i]) {
          curans++;
          if (PC[j] <= C[j]) {
            if (B[j][C[j]] >= 2) {
              curans++;
              curcount *= B[j][C[j]] - 1;
            }
          } else if (PC[j] > C[j]) {
            if (B[j][C[j]]) {
              curans++;
              curcount *= B[j][C[j]];
            }
          }
        } else {
          int Min = PC[j], Max = C[j];
          if (Min > Max) swap(Max, Min);
          if (B[j][Min] >= 1) {
            if (B[j][Max] >= 2) {
              curans += 2;
              curcount *= B[j][Min] * (B[j][Max] - 1);
            } else {
              curans++;
              curcount *= 2;
            }
          } else {
            if (B[j][Max]) {
              curans++;
              curcount *= B[j][Max];
            }
          }
        }
        curcount %= MOD;
      };
      if (curans > ans) {
        ans = curans;
        count = curcount;
      } else if (curans == ans) {
        count += curcount;
        count %= MOD;
      }
    }
    cout << ans << " " << count << endl;
  }
} NSPACE;
int main() {
  ;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
