#include <bits/stdc++.h>
using namespace std;
int card[3][3];
int solve() {
  int n, m;
  cin >> n >> m;
  string s(n, '0');
  vector<bool> check(n, false);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int d;
    cin >> d;
    char c;
    cin >> c;
    d--;
    if (n > 1 && d == 0 && c == '0') ok = false;
    if (check[d]) {
      if (s[d] != c) ok = false;
    } else {
      s[d] = c;
      check[d] = true;
    }
  }
  if (ok)
    cout << s << endl;
  else
    cout << -1 << endl;
}
int main() {
  solve();
  return 0;
}
