#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int number[1000][3];
  int i, j;
  for (i = 0; i < 10; i++) {
    number[i][0] = -1;
    number[i][1] = -1;
    number[i][2] = i;
  }
  for (i = 10; i < 100; i++) {
    number[i][2] = i % 10;
    number[i][1] = (i - (i % 10)) / 10;
    number[i][0] = -1;
  }
  for (i = 100; i < 1000; i++) {
    number[i][2] = i % 10;
    number[i][1] = ((i % 100) - (i % 10)) / 10;
    number[i][0] = (i - (i % 100)) / 100;
  }
  int startnum, endnum;
  if (N = 1) {
    startnum = 0;
    endnum = 9;
  }
  if (N = 2) {
    startnum = 10;
    endnum = 99;
  }
  if (N = 3) {
    startnum = 100;
    endnum = 999;
  }
  int s[M], c[M];
  int S, count;
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (i = startnum; i <= endnum; i++) {
    for (j = 0; j < M; j++) {
      count = 0;
      S = s[j] - 1;
      if (number[i][S] != c[j]) {
        break;
      }
      if (j == M - 1) {
        cout << i;
        count = 1;
        break;
      }
    }
    if (count == 1) break;
    if (i == endnum) {
      cout << "-1";
    }
  }
  return 0;
}
