#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  const int N = (int)1e5 + 10;
  int a[N], b[N];
  vector<int> positions[N];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    positions[b[i]].push_back(i);
  }
  long long dp[n + 1][m + 1];
  dp[0][0] = 1;
  for (int i = 1; i <= m; i++) {
    dp[0][i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 1;
  }
  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];
      if (a[i] == b[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
      }
    }
  }
  cout << dp[n][m] << endl;
}
