#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (x % y) ? gcd(y, x % y) : y; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
using Graph = vector<vector<long long>>;
long long inf = 300000000000000000;
const double PI = 3.14159265358979323846;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n];
  int t[m];
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  for (int i = 0; i < (int)(m); i++) cin >> t[i];
  long long p = 1000000007;
  int dp[n + 1][m + 1];
  for (int i = 0; i < (int)(n + 1); i++) dp[i][0] = 1;
  for (int i = 0; i < (int)(m + 1); i++) dp[0][i] = 1;
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % p;
      else
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % p;
    }
  }
  cout << dp[n][m] << endl;
}
