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