#include <bits/stdc++.h>
using namespace std;
#define omen ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
bool isPrime(int num) {
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) return false;
}
return true;
}
int nextPrime(int n) {
int current = n + 1;
while (true) {
if (isPrime(current)) return current;
else current++;
}
}
int main() {
omen;
int n, m;cin >> n >> m;
if (isPrime(m) && nextPrime(n) == m) cout << "YES" << endl; else cout << "NO" << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgb21lbiBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZShudWxscHRyKTsgY291dC50aWUobnVsbHB0cik7CiNkZWZpbmUgbGwgbG9uZyBsb25nCgpib29sIGlzUHJpbWUoaW50IG51bSkgewogICAgZm9yIChpbnQgaSA9IDI7IGkgPD0gc3FydChudW0pOyBpKyspIHsKICAgICAgICBpZiAobnVtICUgaSA9PSAwKSByZXR1cm4gZmFsc2U7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKaW50IG5leHRQcmltZShpbnQgbikgewogICAgaW50IGN1cnJlbnQgPSBuICsgMTsKICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgaWYgKGlzUHJpbWUoY3VycmVudCkpIHJldHVybiBjdXJyZW50OwogICAgICAgIGVsc2UgY3VycmVudCsrOwogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIG9tZW47CiAgICBpbnQgbiwgbTtjaW4gPj4gbiA+PiBtOwogICAgaWYgKGlzUHJpbWUobSkgJiYgbmV4dFByaW1lKG4pID09IG0pIGNvdXQgPDwgIllFUyIgPDwgZW5kbDsgZWxzZSBjb3V0IDw8ICJOTyIgPDwgZW5kbDsKICAgIHJldHVybiAwOwp9Cg==