#include<iostream>
using namespace std;
#define MOD 1000000007
long long a[1000000];
long long c[1000000];
long long dist[100000000];
long long sum;
int n, q;
long long power(int a, int b) {
long long res = 1;
for (int j = 1; j <= b; j++) {
res *= a;
res %= MOD;
}
return res;
}
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 i = 2; i <= n; i++) {
dist[i] = power(a[i - 1], a[i]);
}
for (int i = 1; i <= q + 1; i++) {
if (c[i - 1] < c[i]) {
for (int j = c[i - 1] + 1; j <= c[i]; j++) {
sum += dist[j];
sum %= MOD;
}
}
else {
for (int j = c[i - 1]; j >= c[i] + 1; j--) {
sum += dist[j];
sum %= MOD;
}
}
}
cout << sum << endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIE1PRCAxMDAwMDAwMDA3Cgpsb25nIGxvbmcgYVsxMDAwMDAwXTsKbG9uZyBsb25nIGNbMTAwMDAwMF07CmxvbmcgbG9uZyBkaXN0WzEwMDAwMDAwMF07CmxvbmcgbG9uZyBzdW07CmludCBuLCBxOwoKbG9uZyBsb25nIHBvd2VyKGludCBhLCBpbnQgYikgewoJbG9uZyBsb25nIHJlcyA9IDE7Cglmb3IgKGludCBqID0gMTsgaiA8PSBiOyBqKyspIHsKCQlyZXMgKj0gYTsKCQlyZXMgJT0gTU9EOwoJfQoJcmV0dXJuIHJlczsKfQoKaW50IG1haW4oKSB7CgljaW4gPj4gbiA+PiBxOwoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CgkJY2luID4+IGFbaV07Cgl9CgljWzBdID0gMTsKCWNbcSArIDFdID0gMTsKCWZvciAoaW50IGkgPSAxOyBpIDw9IHE7IGkrKykgewoJCWNpbiA+PiBjW2ldOwoJfQoJZm9yIChpbnQgaSA9IDI7IGkgPD0gbjsgaSsrK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