#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n], t[m];
  for (int i = 0; i < (int)n; i++) cin >> s[i];
  for (int i = 0; i < (int)m; i++) cin >> t[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (int i = 0; i < (int)n + 1; i++) dp[i][0] = 1;
  for (int i = 0; i < (int)m + 1; i++) dp[0][i] = 1;
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)m; j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
      else
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
