import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.bitmanip;

final class PrimeTable {
  private:
  BitArray a;
  size_t n;
  public:
  pure nothrow @nogc
  bool isPrime (size_t i) const {
    return (i & 1) ? !a[i>>>1] : (i == 2);
  }
  pure
  this (size_t _n) {
    n = _n;
    auto m = n >> 1;
    a.length = max (1, m);
    a[0] = true;
    foreach (i; 1 .. ceil((sqrt (n.to!(double)) - 1.0)).to!(size_t)) {
      if (!a[i]) {
        immutable k = (i << 1) + 1;
        for (size_t j = 2 * i * (i + 1); j < m; j += k) {
          a[j] = true;
        }
      }
    }
  }
}


void main() {
  int x;
  readf (" %d", &x);
  auto pt = new PrimeTable (x + 100000);
  while (!pt.isPrime(x)) ++x;
  writeln (x);
}

