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