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