class Main {

  public static void main(String[] args) 
  {
    System.out.println(transform(123456789,7,8));
  }

  public static int transform(int n, int p, int d)
  {
    //converts int n to String num
    String num = Integer.toString(n);
    //length of num
    int l = num.length();
    //finds the pth digit of n from the right
    int pDigit = Integer.parseInt(num.substring(l-p, l-p+1));
    //if the pth digit is between 0 and 4
    if (pDigit <= 4)
    {
      //add d to the pth digit
      //and replace the pth digit by the
      //units digit of the sum
      pDigit = (pDigit + d)%10;
      //new num
      num = num.substring(0,l-p) + Integer.toString(pDigit);
      //replace all digits to the right of 
      //the pth digit by 0
      //loop goes from the pth digit until the units digit
      for (int i = l-p+1; i < l; i++)
      {
        num += "0";
      }
    }
    //if the pth digit is between 5 and 9
    if (pDigit > 4)
    {
      //subtract d from the pth digit
      //and replace the pth digit by the
      //leftmost digit of the absolute value of the difference
      pDigit = Integer.parseInt(Integer.toString(Math.abs(pDigit - d)).substring(0,1));
      //new num
      num = num.substring(0,l-p) + Integer.toString(pDigit);
      //replace all digits to the right of 
      //the pth digit by 0
      //loop goes from the pth digit until the units digit
      for (int i = l-p+1; i < l; i++)
      {
        num += "0";
      }
    }
    return Integer.parseInt(num);
  }
}