#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int keta[n];
  int count = 0;
  int ans = -1;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < m; j++) {
        if (i != c[j]) {
          break;
        }
        if (j == m - 1) {
          ans = i;
          goto END;
        }
      }
    }
  } else {
    for (int i = 10; i < 1000; i++) {
      count = 0;
      int kari = i;
      while (kari > 0) {
        keta[count] = kari % 10;
        kari = kari / 10;
        count++;
      }
      if (count != n) {
        continue;
      }
      reverse(keta, keta + n);
      for (int j = 0; j < m; j++) {
        if (keta[s[j] - 1] != c[j]) {
          break;
        }
        if (j == m - 1) {
          ans = i;
          goto END;
        }
      }
    }
  }
END:
  cout << ans;
}
