#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e3 + 23;
const int maxm = 1e5 + 15;
vector<int> ve[maxm];
int n, m, a[maxn], b[maxn];
long long dp[maxn][maxn];
int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; ++i) dp[i][0] = 1;
  for (int i = 0; i <= m; ++i) dp[0][i] = 1;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    ve[a[i]].push_back(i);
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i][j - 1];
      for (int k = 0; k < (int)ve[b[j]].size(); ++k) {
        dp[i][j] += dp[ve[b[j]][k] - 1][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n][m];
  return 0;
}
