#include <bits/stdc++.h>
using namespace std;
bitset<1000006> mark;
vector<int> primes;
void sieve() {
  mark[0] = mark[1] = 1;
  primes.push_back(2);
  int lim = sqrt(1000006 * 1.0) + 2;
  for (int i = 4; i < 1000006; i += 2) mark[i] = 1;
  for (int i = 3; i < 1000006; i += 2) {
    if (!mark[i]) {
      primes.push_back(i);
      if (i <= lim)
        for (int j = i * i; j < 1000006; j += i) mark[j] = 1;
    }
  }
}
int main() {
  sieve();
  long long n, m;
  cin >> n >> m;
  long long p = 10000, q = 10000;
  for (long long i = 0; i < 100; i++) {
    if (primes[i] == n) p = i;
    if (primes[i] == m) q = i;
  }
  if (abs(p - q) == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
