#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char> > ss;
  for (int i = 1; i <= m; i++) {
    int a;
    char b;
    cin >> a >> b;
    ss.push_back(make_pair(a, b));
  }
  char st[1000] = {};
  for (int i = 1; i <= n; i++) {
    st[i] = '0';
  }
  bool ok = true;
  for (int i = 0; i < ss.size(); i++) {
    int a = ss[i].first;
    char b = ss[i].second;
    if (a == 1 && b == '0') {
      ok = false;
      break;
    } else if (st[a] == '0') {
      st[a] = b;
    } else if (st[a] != b) {
      ok = false;
      break;
    }
  }
  if (st[1] == '0') {
    cout << "-1" << endl;
  } else if (ok == true) {
    for (int i = 1; i <= n; i++) {
      cout << st[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
