#include <bits/stdc++.h>
using namespace std;
int findNextPrime(int n);
bool isPrime(int n);
int main() {
  int n, m;
  cin >> n >> m;
  int nextPrime = findNextPrime(n);
  if (nextPrime == m) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
int findNextPrime(int n) {
  n++;
  while (!isPrime(n)) {
    n++;
  }
  return n;
}
bool isPrime(int n) {
  for (int i = 2; i <= (int)sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
