#include <bits/stdc++.h>
using namespace std;
const int maxn = 2003;
long long dp[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i <= n - 1; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i <= m - 1; ++i) {
    cin >> t[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i][j] + dp[i - 1][j - 1] + 1;
      }
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] + 1 << "\n";
  return 0;
}
