#include <stdio.h>

int sum_of_divisors(int num) {
    int sum = 0;
    int i;
    for (i = 1; i < num; ++i) {
        if (num % i == 0) {
            sum += i;
        }
    }
    return sum;
}

int main(void) {
    int m;
    scanf("%d", &m);

    int max_perfect_num = 0;
    int i;
    for (i = 1; i <= m; ++i) {
        if (sum_of_divisors(i) == i) { 
            max_perfect_num = i;
        }
    }

    printf("%d",max_perfect_num);

    return 0;
}

