#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long x) {
  if (x <= 1) return false;
  if (x <= 3) return true;
  if (x % 2 == 0 || x % 3 == 0) return false;
  for (long long i = 5; i * i <= x; i += 6) {
    if (x % i == 0 || x % (i + 2) == 0) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  bool found = false;
  for (int i = n + 1; i < m; i++) {
    if (isPrime(i)) {
      found = true;
      break;
    }
  }
  if (found)
    cout << "NO" << endl;
  else if (isPrime(m))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
