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