#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n + 1);
  vector<long long> t(m + 1);
  for (long long i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 1; i <= m; i++) cin >> t[i];
  vector<vector<long long> > dp(2, vector<long long>(m + 1, 1));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i] == t[j])
        dp[i % 2][j] = (dp[1 - i % 2][j] + dp[i % 2][j - 1] + 10 * 1000000007) %
                       1000000007;
      else
        dp[i % 2][j] = (dp[1 - i % 2][j] + dp[i % 2][j - 1] -
                        dp[1 - i % 2][j - 1] + 10 * 1000000007) %
                       1000000007;
    }
  }
  cout << max(dp[0][m], dp[1][m]);
}
