#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M, s[10], c[10], ans = -1, low = 0, up = 0;
  cin >> N >> M;
  for (int i = (1); i < ((1) + (M)); i++) {
    cin >> s[i] >> c[i];
  }
  switch (N) {
    case 1: {
      low = 0;
      up = 9;
    }
    case 2: {
      low = 10;
      up = 99;
    }
    case 3: {
      low = 100;
      up = 999;
    }
    default: {
    }
  }
  for (int i = low; i <= up; i++) {
    int d[5];
    if (i < 10) {
      d[1] = i % 10;
      d[2] = -1;
      d[3] = -1;
    }
    if (i >= 10 && i < 100) {
      d[3] = -1;
      d[2] = i % 10;
      d[1] = (i) / 10;
    }
    if (i >= 100 && i < 1000) {
      d[1] = i / 100;
      d[2] = (i - 100 * d[1]) / 10;
      d[3] = i % 10;
    }
    int flg__ = 1;
    for (int j = (1); j < ((1) + (M)); j++) {
      if (d[s[j]] != c[j]) {
        flg__ = 0;
        j = 100000;
      }
    }
    if (flg__) {
      ans = i;
      i = 10000000;
    }
  }
  cout << ans;
  return 0;
}
