#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<vector<long long>> dp;
vector<vector<int>> I;
vector<int> S, T;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  dp.resize(n + 1);
  S.resize(n);
  T.resize(m);
  I.resize(m);
  for (int i = 0; i < n; i++) {
    dp[i].resize(m + 1);
    cin >> S[i];
  }
  dp[n].resize(m + 1);
  dp[0][0] = 1;
  for (int i = 0; i < m; i++) {
    I[i].resize(100001, -1);
    if (i) copy(I[i - 1].begin(), I[i - 1].end(), I[i].begin());
    dp[0][i + 1] = 1;
    dp[i + 1][0] = 1;
    cin >> T[i];
    I[i][T[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int G = I[j - 1][S[i - 1]];
      if (G == -1) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i][G];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m];
}
