#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int INF = 1e9;
const int MOD = INF + 7;
string s;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (auto& i : a) cin >> i;
  ;
  for (auto& i : b) cin >> i;
  ;
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  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++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      if (a[i - 1] != b[j - 1]) dp[i][j] -= dp[i - 1][j - 1];
      if (dp[i][j] >= MOD) dp[i][j] -= MOD;
    }
  }
  cout << dp[n][m] << '\n';
}
