#include <bits/stdc++.h>
using namespace std;
int main() {
  int s, n, m, g, h;
  cin >> n >> m;
  int t[m][2];
  int p[n];
  for (int i = 0; i < m; i++) {
    cin >> t[i][0] >> t[i][1];
    t[i][0]--;
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (t[i][0] == t[j][0]) {
        if (t[i][1] != t[j][1]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    if (n != 1 && t[i][0] == 0 && t[i][1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n == 1) s = 1;
  if (n == 2) s = 10;
  if (n == 3) s = 100;
  for (int i = s - 1; i < 10 * s; i++) {
    h = i;
    g = 1;
    for (int j = 0; j < n; j++) {
      p[n - j - 1] = h % 10;
      h = h / 10;
    }
    for (int k = 0; k < m; k++) {
      for (int j = 0; j < n; j++) {
        if (t[k][0] == j) {
          if (t[k][1] != p[j]) g = 0;
        }
      }
    }
    if (g) {
      cout << i << endl;
      return 0;
    } else if (h == 10 * s - 1)
      cout << "-1" << endl;
  }
}
