#include <bits/stdc++.h>
using namespace std;

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
constexpr int INF = 0x3f3f3f3f; constexpr ll BINF = 0x3f3f3f3f3f3f3f3fLL;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

// ModInt Template {{{
class mint {
private:
	int x;
	static const int MOD = 1'000'000'007;

public:
	friend inline std::ostream &operator<<(std::ostream &os, const mint &arg) {
		return os << arg.x;
	}
	friend inline std::istream &operator>>(std::istream &is, mint &arg) {
		is >> arg.x;
		if (arg.x >= MOD) arg.x -= MOD;
		return is;
	}
	mint(const int &x) : x(x) {
		if (this->x >= MOD) this->x -= MOD;
	}
	mint(const long long &x) : x(x % MOD) {}
	mint() : x(0) {}

	mint &operator+=(const mint &rhs) {
		x += rhs.x;
		if (x >= MOD) x -= MOD;
		return *this;
	}
	mint &operator++() {
		return *this += 1;
	}
	mint operator+(const mint &rhs) const {
		return mint(*this) += rhs;
	}
	mint operator++(int) {
		mint cpy(*this);
		++*this;
		return cpy;
	}

	mint &operator-=(const mint &rhs) {
		x -= rhs.x;
		if (x < 0) x += MOD;
		return *this;
	}
	mint &operator--() {
		return *this -= 1;
	}
	mint operator-(const mint &rhs) const {
		return mint(*this) -= rhs;
	}
	mint operator-() const {
		return mint() - *this;
	}
	mint operator--(int dummy) {
		mint cpy(*this);
		--*this;
		return cpy;
	}

	mint &operator*=(const mint &rhs) {
		x = 1LL * x * rhs.x % MOD;
		return *this;
	}
	mint operator*(const mint &rhs) const {
		return mint(*this) *= rhs;
	}

	mint pow(long long p) const {
		mint rt = 1, b = *this;
		for (;p;p>>=1,b*=b) if (p & 1) rt *= b;
		return rt;
	}

	mint &operator/=(const mint &rhs) {
		return *this *= rhs.pow(MOD - 2);
	}
	mint operator/(const mint &rhs) const {
		return mint(*this) /= rhs;
	}

	bool operator<(const mint &rhs) const {
		return x < rhs.x;
	}
	bool operator>(const mint &rhs) const {
		return x > rhs.x;
	}
	bool operator<=(const mint &rhs) const {
		return x <= rhs.x;
	}
	bool operator>=(const mint &rhs) const {
		return x >= rhs.x;
	}
	bool operator==(const mint &rhs) const {
		return x == rhs.x;
	}
	bool operator!=(const mint &rhs) const {
		return x != rhs.x;
	}

	explicit operator int() const {
		return x;
	}

};
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vi s(n), t(m); cin >> s >> t;
	using vm = vector<mint>;
	using vvm = vector<vm>;
	vvm dp(n, vm(m));
	for (int i=0;i<n;i++) for (int j=0;j<m;j++) {
		if (i > 0) dp[i][j] += dp[i - 1][j];
		if (j > 0) dp[i][j] += dp[i][j - 1];
		if (i > 0 && j > 0) dp[i][j] -= dp[i - 1][j - 1];
		if (s[i] == t[j]) {
			if (i > 0 && j > 0) dp[i][j] += dp[i-1][j-1];
			dp[i][j]++;
		}
	}
	cout << dp[n-1][m-1] + 1 << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 16000