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