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