#include <bits/stdc++.h>
using namespace std;
int a[5][2];
int main() {
  int n, m, c, d, flag = 1, mn = 9;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> c >> d;
    if (c == 1 && d == 0 && n != 1) {
      flag = 0;
      break;
    }
    if (a[c][1] == 0) {
      a[c][1] = 1;
      a[c][0] = d;
      mn = c;
    } else if (a[c][0] != d) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    for (int i = 1; i <= n; i++) {
      if (i == 1 && a[i][0] == 0) {
        cout << 1;
      } else {
        cout << a[i][0];
      }
    }
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
