#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
long long int dp[2005][2005];
int a[2005], b[2005];
int n, m;
vector<int> idx[MAX];
int SIZE[MAX];
long long int recur(int l, int r) {
  if (l >= n) return 0;
  long long int &ret = dp[l][r];
  if (~ret) return ret;
  ret = 0;
  int cur = a[l];
  int sz = SIZE[cur];
  int lo = lower_bound(idx[cur].begin(), idx[cur].end(), r) - idx[cur].begin();
  for (int i = lo; i < sz; i++) {
    ret += recur(l + 1, idx[cur][i] + 1) + 1;
  }
  ret += recur(l + 1, r);
  ret %= MOD;
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    idx[b[i]].push_back(i);
    SIZE[b[i]]++;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= 1e5 + 5; i++) idx[i].push_back(3000);
  cout << (recur(0, 0) + 1) % MOD << endl;
  return 0;
}
