#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[n + 1];
  int t[m + 1];
  const long long mod = 1e9 + 7;
  for (int i = 1; i < n + 1; i++) {
    cin >> s[i];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> t[i];
  }
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (int i = 0; i < n + 1; i++) {
    dp[i][0] = 1;
  }
  for (int k = 0; k < m + 1; k++) {
    dp[0][k] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int k = 1; k < m + 1; k++) {
      if (s[i] == t[k]) {
        dp[i][k] =
            dp[i - 1][k] + dp[i][k - 1] - dp[i - 1][k - 1] + dp[i - 1][k - 1];
      } else {
        dp[i][k] = dp[i - 1][k] + dp[i][k - 1] - dp[i - 1][k - 1];
      }
      dp[i][k] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
