#include <stdio.h>
#include <stdlib.h>

// convert a stream of integer rgb pixel values to textual ppm formatted data

int ch;

void read_char() {
  if (ch == -1)
    return;
  else {
    ch = getchar();
    return;
  }
}

void skip_blanks() {
  while (ch == 32 || ch == 10 || ch == 13)
    ch = getchar();
  return;
}

int scan_int() {
  int sum;
  int negative;

  sum = 0; // initialize sum
  negative = 0; // initialize sign as positive

  skip_blanks();
     
  if (ch == 45) { // '-'
    negative = 1;  
    read_char();
  }

  while (ch >= 48 && ch <= 57) { // '0' .. '9'
    sum = sum * 10 + ch - 48;
    read_char();
  }

  if (negative == 1)
    sum = - sum;
  return sum;
}

int main() {
  int i;
  int j;
  int width;
  int height;
  int datum;
  int n;
  int r;
  int g;
  int b;

  ch = ' ';
  
  width = scan_int();
  height = scan_int();

  printf("P3");
  printf("\n");
  printf("%d", width);
  printf(" ");
  printf("%d", height);
  printf("\n");
  printf("255");
  printf("\n");

  n = width * height;
  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      datum = scan_int();
      r = datum & 0x000000ff;
      g = (datum >> 8) & 0x000000ff;
      b = (datum >> 16) & 0x000000ff;
      printf("%d", r);
      printf(" ");
      printf("%d", g);
      printf(" ");
      printf("%d", b);
      printf(" ");
    }
    printf("\n");
  }

  return 0;
}
