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