#include <cstdio>
#include <string>
#include <ctime>
#include <vector>
#include <iterator>
#include <algorithm> // #include <iostream> // using namespace std; srand(time(NULL))
#include <iostream>

std::vector<int> compare (std::vector<int> n1, std::vector<int> n2){
    std::vector<int> compare_result;
    
    std::size_t n1_size = n1.size();
    std::size_t n2_size = n2.size();

    // n1について，n2におけるどの位置に値するかを記録しておくvector配列
    std::vector<int> n1_iterator(n1_size);

    bool forEnd = false;
    for(int i = 0; i < n1_size; i++){
        for(int j = 0; j < n2_size; j++){
            if(i ==0 && j == 0 && n1[n1_size - 1] <= n2[0]){
                n1_iterator[n1_size - 1] = 0;
                forEnd = true;
            }
            if(forEnd){
                break;  
            }
            if(n1[n1_size-1-i] <=n2[j]) {
                n1_iterator[n1_size-1-i] = j;
                break;
            }
            if(j == n2_size-1){
                n1_iterator[n1_size-1-i] = n2_size;
            }
        }
        if(forEnd){
            break;  
        }
    }

    // n1_which，n2_which：各々についてのiterator
    int n1_which = 0;
    int n2_which = 0;
    
    // n1_iteratorの末尾が0であるときに関して，n1_iteratorの全要素が0になるのでそれを代入する．
    if(n1_iterator[n1_size - 1] == 0){
        for(int j = 0; j <n1_size; j++){
            n1_iterator[j] = 0;
        }
    }

    while((n2_which <= n2_size - 1) || (n1_which <= n1_size - 1)){
        if(n1_which != n1_size) {
            if (n1_iterator[n1_which] > n2_which ){
                compare_result.push_back(n2[n2_which]);
                n2_which++;
            }
            else {
                compare_result.push_back(n1[n1_which]);
                n1_which++;
            }
        }
        else{
            compare_result.push_back(n2[n2_which]);
            n2_which++; 
        }
    }
    
    return compare_result;
}

std::vector<int> merge (std::vector<int> n){ // int merge (string *s, int N, std::vector<int> n){
    
    std::size_t n_size = n.size();
    if (n_size <= 2){
        if (n_size != 1) {
            if(n[0] > n[1]){
                int x = n[0];
                std::iter_swap(n.begin(),n.begin()+1);
            }
        } 
        return n;
    } else {
        std::vector<int> n1,n2;
        copy(n.begin(), std::next(n.begin(), (int) n_size/2),back_inserter(n1));
        int xx = n_size /2;
        copy(std::next(n.begin(), xx), n.end(), back_inserter(n2));
        // return n2;
        return compare(merge(n1), merge(n2));
    }
}

int main () {
  int X;
  std::cin >> X;
  std::vector<int> list;
  int sub = 0;
  for (int i = 2; i < 32; i++ ) {
    for (int j = 2; j < 11; j++) {
      if (j == 2) {
        sub = i*i;
        if (sub > 1000) {
          break;
        } 
        list.push_back(sub);
      }
      else {
        sub = sub * i;
        if (sub > 1000) {
          break;
        }
        else {
          list.push_back(sub);
        }
      }
    }
  }

  list = merge(list);
  for (int i = 0; i < list.size(); i++ ) {
    if (X < list[i]) {
      if (i != 0) {
        std::cout << list[i-1] << std::endl;
        break;
      }
      else {
        std::cout << 1 << std::endl;
        break;
      }
    }
    if (i == (list.size()-1)) {
      std::cout << 1000 << std::endl;
    }
  }
}


Measured memory_bytes: 256