public static void main(String[] args) {
		ArrayList results = new ArrayList();
		BigInteger a = new BigInteger("2");
		while(a.intValue() <= 100) {
			for (int b = 2; b <= 100; b++) {
				if (!results.contains(a.pow(b).toString())) {
					results.add(a.pow(b).toString());
				}
			}
			a = a.add(BigInteger.ONE);
		}
		int answer = 0;
		for (int count = 0; count < 9183; count++) {
			String digits;
			digits = results.get(count).toString();
			int digitSum = 0;
			for (int insideCount = 0; insideCount < digits.length(); insideCount++) {
				digitSum += Integer.parseInt(digits.substring(insideCount,insideCount+1));
			}
			if (answer < digitSum) {
				answer = digitSum;
			}
		}
		System.out.println(answer);
	}