import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class B17626_Before {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for (int i = 1; i <= (int) Math.sqrt(n); i++) { // 한 제곱수를 넣은 리스트
list1.add((int) Math.pow(i, 2));
}
for (int i = 1; i <= (int) Math.sqrt(n); i++) { // 두 제곱수를 더한 리스트
for (int j = i; j <= (int) Math.sqrt(n); j++) {
list2.add((int) (Math.pow(i, 2) + (Math.pow(j, 2))));
}
}
int answer = 4; // 4로 초기화해놓고
if (list1.contains(n)) answer = 1; // list1 에 있으면 한 수로 만들 수 있음
else if (list2.contains(n)) answer = 2; // list2 에 있으면 두 수로 만들 수 있음
else {
for (int m : list1) { // list2 를 돌면서
if (list2.contains(n - m)) { // 만약, n-m 이 list2에 있다면? n-m 과 m 으로 만들 수 있음
answer = 3; // m 은 두 수로 이루어져 있기 때문에 3 리턴
}
}
}
System.out.println(answer);
}
}