#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long inf = 1ll << 61;
struct edge {
  long long to;
  long long to2;
  long long cost;
};
long long s[2005], t[2005];
long long dp[2006][2006];
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  for (long long i = 0; i < n + 1; i++) dp[i][0] = 1;
  for (long long i = 0; i < m + 1; i++) dp[0][i] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
      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;
}
