#include <bits/stdc++.h>
int main() {
  uint32_t nn;
  uint32_t mm;
  uint32_t tar;
  uint32_t dig1 = 0;
  uint32_t dig2 = 0;
  uint32_t dig3 = 0;
  std::cin >> nn >> mm;
  std::vector<std::vector<int>> vv(2, std::vector<int>(mm, 0));
  for (int i = 0; i < mm; i++) {
    for (int j = 0; j < 2; j++) {
      std::cin >> vv[j][i];
    }
  }
  if (nn == 1) {
    std::cout << "1des" << std::endl;
    for (int i = 0; i < 10; i++) {
      dig3 = i;
      for (int k = 0; k < mm; k++) {
        if (vv[0][k] != 1) {
          goto out3;
        }
        if (dig3 != vv[1][k]) {
          goto out3;
        }
      }
      std::cout << i << std::endl;
      return 0;
    out3:;
    }
  } else if (nn == 2) {
    std::cout << "2des" << std::endl;
    for (int i = 10; i < 100; i++) {
      dig3 = i % 10;
      dig2 = i / 10;
      for (int k = 0; k < mm; k++) {
        if (vv[0][k] == 3) {
          goto out2;
        } else if (vv[0][k] == 1) {
          if (dig2 != vv[1][k]) {
            goto out2;
          }
        } else if (vv[0][k] == 2) {
          if (dig3 != vv[1][k]) {
            goto out2;
          }
        }
      }
      std::cout << i << std::endl;
      return 0;
    out2:;
    }
  } else if (nn == 3) {
    for (int i = 100; i < 1000; i++) {
      dig3 = (i % 100) % 10;
      dig2 = (i % 100) / 10;
      dig1 = i / 100;
      for (int k = 0; k < mm; k++) {
        if (vv[0][k] == 1) {
          if (dig1 != vv[1][k]) {
            goto out;
          }
        }
        if (vv[0][k] == 2) {
          if (dig2 != vv[1][k]) {
            goto out;
          }
        }
        if (vv[0][k] == 3) {
          if (dig3 != vv[1][k]) {
            goto out;
          }
        }
      }
      std::cout << i << std::endl;
      return 0;
    out:;
    }
  }
  std::cout << (-1) << std::endl;
  return 0;
}
