#include <bits/stdc++.h>
using ll = long long int;
using vi = std::vector<int>;
using ii = std::pair<int, int>;
using iii = std::pair<ii, int>;
using vii = std::vector<ii>;
const int N = 1010101;
const int MD = 1e9 + 7;
void solve() {
  int n;
  std::cin >> (n);
  ;
  int m;
  std::cin >> (m);
  ;
  int s[n];
  for (int i = 0; i < (n); ++i) std::cin >> (s[i]);
  int t[m];
  for (int i = 0; i < (m); ++i) std::cin >> (t[i]);
  int dp[n][m];
  dp[0][0] = 1 + (s[0] == t[0]);
  for (int i = (1); i < (n); ++i) dp[i][0] = dp[i - 1][0] + (s[i] == t[0]);
  for (int j = (1); j < (m); ++j) dp[0][j] = dp[0][j - 1] + (s[0] == t[j]);
  for (int i = (1); i < (n); ++i)
    for (int j = (1); j < (m); ++j) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MD;
      if (s[i] == t[j]) (dp[i][j] += dp[i - 1][j - 1]) %= MD;
    }
  std::cout << (dp[n - 1][m - 1]) << " ";
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  solve();
  return 0;
}
