#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string num(n, 'x');
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s = n - s;
    char ch = '0' + c;
    if (num[s] != 'x' && num[s] != ch) {
      cout << -1 << endl;
      return 0;
    } else {
      num[s] = ch;
    }
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == 'x') {
      num[i] = '0';
    }
  }
  reverse(num.begin(), num.end());
  string res = "";
  for (int i = 0; i < n; i++) {
    if (num[i] != '0') {
      while (i < n) {
        res.push_back(num[i]);
        i++;
      }
      break;
    }
  }
  if (res.length() == 0) res = "0";
  if (res.length() != n) {
    cout << -1 << endl;
    return 0;
  }
  cout << res << endl;
}
