#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string k = "";
  for (int i = 0; i < n; i++) {
    k = k + "0";
  }
  int m;
  cin >> m;
  while (m--) {
    int p;
    char q;
    cin >> p;
    cin >> q;
    if (k[p - 1] != '0') {
      if (q == k[p - 1]) {
        continue;
      }
      cout << "-1";
      return 0;
    }
    k[p - 1] = q;
  }
  while (k.front() == '0') {
    k = k.substr(1);
  }
  if (k.size() == 0) {
    cout << "-1";
  } else {
    cout << k;
  }
}
