<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = $Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	$start = $inp_N - (int)($inp_N / $inp_K);
	//for ($i = 1; $i <= $inp_N; $i++) {
	/for ($i = $start; $i <= $inp_N; $i++) {
		$temp = $i;
		$sum = 0;
		while ($temp !== 0) {
			$sum += $temp;
			//$temp = $temp / $inp_K;
			$temp = (int)($temp / $inp_K);
		}
		//if ($sum > $inp_N) {
		if ($sum >= $inp_N) {
			$V = $i;
			break;
		}
	}
	printf("%d", $V);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>


<?php
$a = trim(fgets(STDIN));
$b = array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");
for($x = 0; $x < $a; $x++)
{
    if($x == $a - 1)
    {
        print $b[0];
        break;
    }
    else
    {
        array_push($b, $b[0]);
        array_push($b, $b[0]);
        array_splice($b, 0, 1);
    }
}
?>


<?php
$a = trim(gfets(STDIN));
$arr = array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");

while($a > 0){
	$tmp = $arr[0];
	$arr = array_slice($arr, 1);
	$arr[] = $tmp;
	$arr[] = $tmp;
	$a--;
}
echo $arr[0];
?>


<?php
$a = trim(fgets(STDIN));
$arr = array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");

while($a > 0){
	$tmp = $arr[0];
	$arr = array_slice($arr, 1);
	$arr[] = $tmp;
	$arr[] = $tmp;
	$a--;
}
echo $arr[0];
?>


<?php
$a = trim(fgets(STDIN));
$arr = array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");
$a--;
while($a > 0){
	$tmp = $arr[0];
	$arr = array_slice($arr, 1);
	$arr[] = $tmp;
	$arr[] = $tmp;
	$a--;
}
echo $arr[0];
?>


<?php
list($s)=explode(" ", trim(fgets(STDIN)));
for($n=0,$m=0,$k=1;$k+5*pow(2,$n)<$s;$n++)
$k+=5*pow(2,$n);
while($k+$m*pow(2,$n)<=$s): $m++;
endwhile;
switch($m){
   case 1:print "Sheldon"; break;
   case 2:print "Leonard"; break;
   case 3:print "Penny"; break;
   case 4:print "Rajesh"; break;
   case 5:print "Howard"; break;
}
?>


<?php
   $n = trim(fgets(STDIN));
   $names = Array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");
   $m = 5;
   $sum = 5;
   $count = 1;
   while($sum<$n){
       $m *= 2;
       $sum += $m;
       $count *= 2;
   }
   if ($sum>$n) $sum -= $m;
   $n -= $sum;
   $n = ceil($n/$count);
   echo $names[$n-1];
?>


<?php
$n = fgets(STDIN);
$i=0;
$que=array(" ","Sheldon", "Leonard", "Penny", "Rajesh", "Howard" );$queEnd=5;$queStart=1;
function put()
{
    global $que;global $queEnd;global $current;
    $queEnd++;
    $que[$queEnd]=$current;
}
function get()
{
    global $current;global $queStart; global $que;
    $current = $que[$queStart];
    $queStart++;
}
while ($i!=$n)
{
    get();
    put();
    put();
    $i++;
}
echo $que[$n];
?>


<?php
    define('DEBUG', 0);

    if(DEBUG) $GLOBALS['file'] = fopen('input.txt', 'r');
    function debug($var){echo '<pre>';print_r($var);echo '</pre>';}
    function read_line()
    {
        if(DEBUG) { $file = $GLOBALS['file'];$line = trim(fgets($file));}
        else $line = trim(fgets(STDIN));
        return $line;
    }
    function get_array($line){return explode(' ', $line);}
    function read_array(){return get_array(read_line());}
    //echo "$s\n";
    /*****************************************************************/

    $n = read_line();

    $people[] = 'Sheldon';
    $people[] = 'Leonard';
    $people[] = 'Penny';
    $people[] = 'Rajesh';
    $people[] = 'Howard';

    for ($i=1; $i<$n; $i++)
    {
        $char = array_shift($people);
        $people[]=$char;
        $people[]=$char;
    }

    echo $people[0];
?>


<?php
    $k = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));

    $sum = 0;
    for ($i=0; $i<$k; $i++)
        $sum += $arr[$i];

    $k++;
    $count=0;
    for ($i=1; $i<=5; $i++)
        if (($sum+$i)%$k==0)
            $count++;
    echo $count;
?>


<?php
$n = trim(fgets(STDIN));
$n = explode(' ', $n);
print $n[0] * $n[1] / 2;
?>


<?php
while($str = fgets(STDIN)){
	$input[] = explode(' ', trim($str));
}
$answer = ($input[0]*$input[1])/2;
echo $answer;
?>


<?php
fscanf(STDIN, "%d %d", $c, $r);
$answer = ($c*$r)/2;
echo $answer;
?>


<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = ($a[0]*$a[1])/2;
echo ceil($b);
?>


<?php
$n = readline("");
$nn = explode(" ", $n);
echo $nn[0]*$nn[1]/2;


<?php

fscanf(STDIN, "%d %d\n", $m, $n);

$x1 = floor($n/2);
$x2 = floor($m/2);

$res1 = $x1 * $m;
$res2 = $x2 * $n;

$res1 = $res1>$res2 ? $res1 : $res2 ;

fwrite(STDOUT, $res1."\n");


<?php

list($x, $y) = explode(' ', fgets(STDIN));

$size = [];
$size[0] = 15;
$size[1] = 13;

if (($x % 2) === 0) {
    $even_x = $x;
    $odd_x = 0;
} else {
    $even_x = $x - 1;
    $odd_x = 1;
}
if (($y % 2) === 0) {
    $even_y = $y;
    $odd_y = 0;
} else {
    $even_y = $y - 1;
    $odd_y = 1;
}

$number = $even_x * $even_y / 2;
$odd_square = $odd_y * $x + $odd_x * $y;

$number += $odd_square / 2;

echo $number;


<?php
$input = file_get_contents("php://stdin");
$input = preg_replace( "/\r|\n/", "", $input);
$e = explode("/",$input);

$s = explode("\n",$e[$c]);

$count=0;
foreach($e as $a)
{

    if($a!="" && $a!='\n')
    {
        echo("/$a");
        $count++;
    }

}
    if($count==1 || $count==0)
    {
        echo("/");
    }

?>


<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $address = fgets($stdin);

    $new_addr = preg_replace("/\/+/", "/", $address);
    fputs($stdout, $new_addr);
?>


<?php
$input=trim(fgets(STDIN));
$array=str_word_count($input, 1);
if (str_word_count($input, 0) == 0) {
       echo "/";
    }else {
echo "/";
foreach ($array as $val) {
 $edit1=$val." ";
 echo $turbo=str_replace(" ", "/", $edit1);
}}
?>


<?php
    function readFiles ($dir) {
        return file_get_contents($dir);
    }
    $dir = 'php://stdin';
    $data = explode(' ', readFiles($dir));
    $squareX = $data[0];
    $squareY = $data[1];
    $tailSize = $data[2];
    echo gmp_mul( ceil($squareX / $tailSize), ceil($squareY / $tailSize) );


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array(" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
unset($c[0]);
$d = array_search($a, $c);
$b += $d;
$e = $b % 12;
print $c[$e];
?>


<?php
$in = trim(fgets(STDIN));
//$in = 'ftphttprururu';

//��������
if(strpos($in,'http')===0){
	$w = 'http';
}else{
	$w = 'ftp';
}
$in = substr($in,strlen($w));
$w .= '://';

//�����
$r = strpos(substr($in,1),'ru');
if($r > 0){
	$w .= substr($in,0,$r+1);
}
$w .= '.ru';
$in = substr($in,($r+3));

if($in<>''){
	$w .= '/'.$in;
}

echo $w;

?>


<?php
list($a, $b, $c, $d, $e, $f) = explode(" ", trim(fgets(STDIN)));
$g = abs($a - $b) * $d;
$h = abs($a - $c) * $e + $f * 2 + abs($a - $b) * $e;
if($h <= $g)
{
     print "YES";
}
else
{
     print "NO";
}
?>


<?php
$str = strtoupper(trim(fgets(STDIN)));
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
$arr_str = array_unique($chars);
$txt = implode('', $arr_str);
$count = preg_match_all('/[AEIOUY]/i', $txt, $m);
echo $count-1;


<?php
$player = str_split(trim(fgets(STDIN)),1);
$inArow=1;
for ($i=1;$i<count($player);$i++)
{
    if ($player[$i]==$player[$i-1])
    {
        $inArow++;
        if ($inArow==7)break;
    }
    else
    {
        $inArow=0;
    }
}
if ($inArow==7)echo "YES";
else echo "NO";
?>


<?php

$file = fopen("php://stdin","r");
$str = trim(fgets($file));
if(strlen($str)>100 || strpos($str, '0')===false || strpos($str, '1')===false)
    echo "NO\n";
else{
    $i=$counter=$flag=0;
    while($i<strlen($str)-1){
        if (strcmp($str[$i], $str[$i+1])==0)
            $counter++;
        else
            $counter=1;
        if ($counter >= 7) {
            $flag=1;
            break;
        }
        $i++;
    }
    echo $flag == 1 ? "YES\n" : "NO\n";
}
fclose($file);


<?php
$str=trim(fgets(STDIN));

	if((substr_count($str,'1111111')==1)||(substr_count($str,'0000000')==1))

		{
          echo "YES";

		}
		else echo "NO";


<?php

$input = readline("Enter");
$arr = str_split($input);
$times = sizeof($arr);
$contador_0 = 0;
$contador_1 = 0;
$atual = 0;

	for($i=0;$i<$times-1;$i++){
			if(current($arr)==0){
				if(current($arr) === next($arr)){
					$contador_0++;

				}
			}else{
				if(current($arr) === next($arr)){
					$contador_1++;

				}

			}

	}

	if($contador_0 == 7 || $contador_1==7){
		echo 'YES';
	}else{
		echo 'NO';
	}


<?php
/**
 * Created by IntelliJ IDEA.
 * User: 低调的程序员
 * Date: 2015/4/25
 * Time: 1:17
 */

while(fscanf(STDIN,"%s",$str)){
    $len=strlen($str)-7;
    $iter=0;
    for(;$iter<$len;$iter++){
        $h=substr($str,$iter,1);
        $t=substr($str,$iter+1,7);
        if($h=="0" and $t=="1111111")break;
        else if($h=="1" and $t=="0000000")break;
    }
    if($iter>=$len || $len<1){
        fprintf(STDOUT,"NO\n");
    }
    else{
        fprintf(STDOUT,"YES\n");
    }
}


<?php
$input =rtrim(fgets(STDIN));
if(strpos($input, '1111111') || strpos($input, '0000000')){
  echo "YES";
}else{
  echo "NO";
}


<?php
$Last = "";
$i = 0;
$f = fopen( 'php://stdin', 'r' );
While ($Input = fgets($f)) {
	if($Last==$Input){
		$i++;
	}else{
$i=0;
}
	$Last = $Input;
	if($i==6){
		echo "YES";
		exit;
	}
}
echo "NO";


<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%s", $encrypted_pass);
$decrypted_pass = $encrypted_pass;
for ($i = 0; $i < 10; $i++) {
    fscanf(STDIN, "%s", $code);
    $decrypted_pass = str_replace($code,$i, $decrypted_pass);
}

printf("%s", $decrypted_pass);


<?php

$stdin = fopen('php://stdin', 'r');

$a = str_split(fgets($stdin));
$b = str_split(fgets($stdin));

$base = ord('a') - ord('A');

$orda = ord('a');

$len = count($a);
$ords = array();

$result = 0;

for($i = 0; $i < $len; $i++)
{
	if(!isset($ords[$a[$i]]))
	{
		$ai = ord($a[$i]);

		if($ai >= $orda)
		{
			$ai -= $base;
		}

		$ords[$a[$i]] = $ai;
	}

	$ai = $ords[$a[$i]];

	if(!isset($ords[$b[$i]]))
	{
		$bi = ord($b[$i]);

		if($bi >= $orda)
		{
			$bi -= $base;
		}

		$ords[$b[$i]] = $bi;
	}

	$bi = $ords[$b[$i]];

	if($ai > $bi)
	{
		$result =  1;
		break;
	}elseif($ai < $bi)
	{
		$result = -1;
	}
}

echo $result;


<?php

$data = [];

while ($item = fgets(STDIN)) {
    $data[] = strtolower($item);
}

if($data[0] === $data[1]) {
    echo 0;
}else {
    $sum1 = 0;
    $sum2 = 0;
    $len1 = strlen($data[0]) - 1;
    $len2 = strlen($data[1]) - 1;
    for($i = 0; $i <= $len1; $i++) {
        $sum1 += ord($data[0][$i]);
    }
    for($i = 0; $i <= $len2; $i++) {
        $sum2 += ord($data[1][$i]);
    }

    if($sum2 < $sum1) {
        echo 1;
    } else {
        echo -1;
    }
}


<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 8/13/2017
 * Time: 8:48 PM
 */

$val = explode(' ', fgets(STDIN));
$arr = explode(' ', fgets(STDIN));
$sum = 0;
$status = 0;
$hold = -1;
$temp = 0;
for($i=0;$i<$val[0];$i++){

	if($arr[$i]>8){
		$sum+=8;
		$arr[$i+1]+=($arr[$i] - 8);
	}
	else{
		$sum+=$arr[$i];
	}
	//print $sum . ' ';
	if($sum>=$val[1]){
		$hold = $i+1;
	}

}
print $hold;
?>