#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n) {
  if (n == 1) return 0;
  if (n <= 3) return 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (is_prime(m) == 0)
    cout << "NO" << endl;
  else {
    int f = 0;
    for (int i = n + 1; i < m; i++) {
      if (is_prime(i) == 1) {
        f++;
        break;
      }
    }
    if (f == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
