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