#include <bits/stdc++.h>
int a[30][30], L[300000], R[300000];
using namespace std;
int main() {
  int n, i, j, m;
  cin >> n >> m;
  i = n;
  j = 0;
  while (j == 0) {
    i++;
    int u = sqrt(i);
    int y = 0;
    while (u >= 2) {
      if (i % u == 0) y = -1;
      u--;
    }
    if (y == 0) j = -1;
  }
  if (i == m)
    cout << "YES";
  else
    cout << "NO";
}
