#include <bits/stdc++.h>
using namespace std;
int CommomSubsequencesCount(vector<int> s, vector<int> t) {
  int n1 = s.size();
  int n2 = t.size();
  long long int dp[n1 + 1][n2 + 1];
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n1; i++) {
    for (int j = 1; j <= n2; j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j]) % 1000000007;
      else
        dp[i][j] =
            (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % 1000000007;
    }
  }
  return (dp[n1][n2] + 1) % 1000000007;
}
int main() {
  vector<int> s, t;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    s.push_back(b);
  }
  for (int i = 0; i < m; i++) {
    int b;
    cin >> b;
    t.push_back(b);
  }
  cout << CommomSubsequencesCount(s, t) << endl;
  return 0;
}
