#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> S(n + 1, 0);
  vector<int> T(m + 1, 0);
  for (int i = 1; i <= n; i++) cin >> S[i];
  for (int i = 1; i <= m; i++) cin >> T[i];
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (S[i] == T[j]) {
        dp[i][j] =
            (1 + (dp[i - 1][j] + dp[i][j - 1]) % 1000000007) % 1000000007;
      } else {
        dp[i][j] =
            ((dp[i - 1][j] + dp[i][j - 1]) + 1000000007 - dp[i - 1][j - 1]) %
            1000000007;
      }
    }
  }
  cout << (dp[n][m] + 1) % 1000000007;
}
