#include "bits/stdc++.h"


#define OPEN  freopen ("ancestor","r" , stdin), freopen ("ancestor","w",stdout);
#define Da ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define p_b push_back
#define max1(a,b,c) max(a,max(b,c))
#define min1(a,b,c) min(a,min(b,c))
#define all(a) a.begin() , a.end() 
#define aza cout<<" ? "<<endl;//>>>>
#define F first
#define S second
#define co continue
#define endl '\n'    
#define pre precision
using namespace std;
const long long N=1e7+9,MOD=1e9+7;
main(){
  Da
  long long n,m,k,su1,su2;
  cin>>n>>m>>k;
  if(n%k!=0){
    while(n%k!=0)n++;
  }
  su1=n;
  if(m%k!=0){
    while(m%k!=0)m++;
  }
  su2=m;
  cout<<max(su1,su2)<<endl;//>>>>
}