#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF32 = INT_MAX;
const ll INF64 = ((ll)INF32 << 29ll);
void reflex() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
const int MOD = 1e9 + 7;
signed main() {
  reflex();
  int n, m;
  cin >> n >> m;
  map<queue<int>, ll> cnt;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  queue<int> q;
  for (int l = 0; l < n; l++) {
    int len = l;
    for (int i = 0; i < n; i++) {
      q.push(a[i]);
      if (i == len) {
        len++;
        cnt[q]++;
        q.pop();
      }
    }
  }
  a.clear();
  a.resize(m);
  for (int& x : a) cin >> x;
  while (!q.empty()) q.pop();
  ll ans = 1;
  for (int l = 0; l < m; l++) {
    int len = l;
    for (int i = 0; i < m; i++) {
      q.push(a[i]);
      if (i == len) {
        len++;
        ans += cnt[q];
        ans %= MOD;
        q.pop();
      }
    }
  }
  cout << ans;
  return false;
}
