#include<iostream>
#include<cmath>
using namespace std;
#define MOD 1000000007
long long a[1000000];
long long c[1000000];
long long y[1000000];
long long z[1000000];
long long result;
long long d[31];
long long res;
int n, q, e, f;
int main() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
c[0] = 1;
c[q + 1] = 1;
for (int i = 1; i <= q; i++) {
cin >> c[i];
}
for (int h = 2; h <= n; h++) {
e = a[h - 1];
f = a[h];
d[0] = e;
for (int i = 1; i < 31; i++) {
d[i] = (long long)(d[i - 1] * d[i - 1]) % MOD;
}
res = 1;
for (int i = 0; i < 31; i++) {
if (f % 2 == 1) {
res *= d[i];
res %= MOD;
}
f /= 2;
}
y[h] = res;
}
z[1] = 0;
for (int i = 2; i <= n; i++) {
z[i] = z[i - 1] + y[i];
}
result = 0;
for (int i = 1; i <= q + 1; i++) {
result += abs(z[c[i]] - z[c[i - 1]]);
result %= MOD;
}
cout << result << endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNtYXRoPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwoKbG9uZyBsb25nIGFbMTAwMDAwMF07CmxvbmcgbG9uZyBjWzEwMDAwMDBdOwpsb25nIGxvbmcgeVsxMDAwMDAwXTsKbG9uZyBsb25nIHpbMTAwMDAwMF07CmxvbmcgbG9uZyByZXN1bHQ7CmxvbmcgbG9uZyBkWzMxXTsKbG9uZyBsb25nIHJlczsKaW50IG4sIHEsIGUsIGY7CgppbnQgbWFpbigpIHsKCWNpbiA+PiBuID4+IHE7Cglmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKCQljaW4gPj4gYVtpXTsKCX0KCWNbMF0gPSAxOwoJY1txICsgMV0gPSAxOwoJZm9yIChpbnQgaSA9IDE7IGkgPD0gcTsgaSsrKSB7CgkJY2luID4+IGNbaV07Cgl9Cglmb3IgKGludCBoID0gMjsgaCA8PSBuOyBoKyspIHsKC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