#include <bits/stdc++.h>
using namespace std;
const long long N = 1000000007;
int main() {
  int n, k, ans1 = 0, ans2 = 0;
  int a[1005];
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    if (a[i] == n) {
      ans1 = n;
    } else {
      ans2 = a[i] * a[i];
    }
  }
  cout << ((ans1 * ans2) % N) << "\n";
}
