#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
bool isPrime(int n) {
  if (n == 2) return true;
  if (n < 2 || (n & 1) != 1) return false;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (isPrime(m) != true)
    cout << "NO" << endl;
  else {
    for (int i = n + 1; i <= m; ++i) {
      if (isPrime(i) == true) {
        if (i == m)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
        return 0;
      }
    }
    cout << "NO" << endl;
  }
  return 0;
}
