#include <bits/stdc++.h>
using namespace std;
int ara[3];
int main() {
  int n, m, i, x, y, a = 1;
  cin >> n >> m;
  char c;
  string s = "";
  for (i = 0; i < n; i++) {
    s += "-";
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (a == 1) {
      c = '0' + y;
      if ((s[x - 1] == '-') || s[x - 1] == c) {
        s[x - 1] = c;
      } else {
        cout << -1 << endl;
        a = 0;
      }
    }
  }
  for (i = 0; i < n; i++)
    if (s[i] == '-') s[i] = '0';
  if (s[0] == '0' && a == 1 && n != 1) {
    cout << -1 << endl;
  } else if (a == 1) {
    cout << s << endl;
  }
}
