#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const double pi = 3.14159265359;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int INF = 1e9;
const long long INFLL = 2e18;
int max_del(int n) {
  if (n % 2 == 0) return n / 2;
  int res = 1;
  for (int i = 3; i * i <= n; i++)
    if (n % i == 0) res = i;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> erat(1000000), primes;
  for (int i = 2; i < 100000; i++)
    if (!erat[i]) {
      primes.push_back(i);
      for (int j = i + i; j < 100000; j += i) erat[j] = 1;
    }
  int ans = INF;
  for (auto i : primes)
    if (i > n)
      break;
    else if (i != n - 1)
      ans = min(ans, 1 + max_del(n - i));
  ans = min(ans, max_del(n));
  ans = min(ans, 3);
  cout << ans;
  return 0;
}
