#include <bits/stdc++.h>
using namespace std;
long long int power_mod(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power_mod(a, x / 2);
  long long int ans = (y * y) % 1000000007;
  if (x % 2) ans = (ans * a) % 1000000007;
  return ans;
}
long long int inv(long long int a) { return power_mod(a, 1000000007 - 2); }
long long int power(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power(a, x / 2);
  long long int ans = (y * y);
  if (x % 2) ans *= a;
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[n + 1], t[m + 1];
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int j = 1; j <= m; j++) cin >> t[j];
  long long int dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) dp[i][0] = 1;
  for (int j = 1; j <= m; j++) dp[0][j] = 1;
  dp[0][0] = 1;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i][j] + dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) %
                 1000000007;
      if (s[i] == t[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % 1000000007;
      }
    }
  }
  cout << dp[n][m] << endl;
}
