#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a1, a2, dp[2003][2003], s[2004], t[2004];
int CommomSubsequencesCount() {
  for (int i = 1; i <= a1; i++) {
    for (int j = 1; j <= a2; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j];
        dp[i][j] = dp[i][j] % mod;
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
        dp[i][j] = dp[i][j] % mod;
      }
    }
  }
  return dp[a1][a2];
}
int main() {
  cin >> a1 >> a2;
  for (int i = 1; i <= a1; i++) cin >> s[i];
  for (int i = 1; i <= a2; i++) cin >> t[i];
  cout << CommomSubsequencesCount() + 1 << endl;
}
