#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, i, j = 1, k, l = 0, n, m, t, s = 0, p, r, ans,
                               w = 0, y, x, lcm, gcd, q, count;
  string str;
  vector<string> vc;
  vector<string> vc2;
  map<long long int, long long int> mp;
  set<string> stringstream;
  cin >> n >> m;
  for (j = n + 1;; j++) {
    l = 0;
    for (i = 2; i <= sqrt(j); i++) {
      if (j % i == 0) {
        l = 1;
        break;
      }
    }
    if (l == 0) {
      if (j == m)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
      return 0;
    }
  }
  return 0;
}
