#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
using namespace std;
long long power(long long x, long long y, long long m) {
  long long temp;
  if (y == 0) return 1;
  temp = (power(x, y / 2, m)) % m;
  if (y % 2 == 0)
    return ((temp % m) * temp);
  else
    return ((x * temp % m) * temp % m) % m;
}
long long inv(long long x) {
  return (power(x, 1000000007 - 2, 1000000007)) % 1000000007;
}
bool comp(long long a, long long b) { return a > b; }
long long DP[2001][2002], maxer, arr[20001], arr2[20001];
vector<vector<long long>> lolz(100001);
long long Recursion(long long n, long long m) {
  if (n == maxer) return 0;
  if (DP[n][m + 1] + 1) return (DP[n][m + 1]);
  DP[n][m + 1] = 0;
  for (auto itr = upper_bound(lolz[arr[n]].begin(), lolz[arr[n]].end(), m);
       itr != lolz[arr[n]].end(); itr++) {
    DP[n][m + 1] = (DP[n][m + 1] + Recursion(n + 1, (*itr)) + 1) % 1000000007;
  }
  DP[n][m + 1] += Recursion(n + 1, m);
  return DP[n][m + 1] % 1000000007;
}
int32_t main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i < 2001; i++) {
    for (long long l = 0; l < 2002; l++) {
      DP[i][l] = -1;
    }
  }
  long long n, m;
  cin >> n >> m;
  maxer = n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i]--;
  }
  for (long long i = 0; i < m; i++) {
    cin >> arr2[i];
    lolz[arr2[i] - 1].push_back(i);
  }
  cout << Recursion(0, -1) + 1;
  return 0;
}
