#include <stdio.h>

int main(void)
{
  char ch;
  unsigned int value;
  unsigned int power9;
  
  while (fread(&ch, 1, 1, stdin))
  {
    value = 0;
    // if I am here, I read one character, not at EOF
    // and the character is read into ch
    do
    {
      if (ch != '\n') 
      {
        // if I am here, I just read a digit
        value = (value * 7) + (ch - '0');
      }
      else
      {
        // we are now at the end of line, nothing to do
      }
    } while ((ch != '\n') && (fread(&ch, 1, 1, stdin) != 0));
    // if I am here, we have a value read and interpreted
    printf("%u\n",value);
    power9 = 9*9*9*9*9;
    while (power9 > 0) 
    {
      unsigned quotient;

      quotient = value / power9;
      ch = quotient + '0';
      fwrite(&ch, 1, 1, stdout);
      value %= power9;
      power9 /= 9;
    }
    ch = '\n';
    fwrite(&ch, 1, 1, stdout);
  }
}

