#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> s(n, '0');
  vector<int> sj(3, 0);
  int j = 0;
  for (int(i) = 0; (i) < (m); (i)++) {
    int sv;
    char v;
    cin >> sv >> v;
    if (sj.at(sv - 1) != 0) {
      if (s.at(sv - 1) != v) {
        j = 1;
        break;
      }
    } else {
      s.at(sv - 1) = v;
      sj.at(sv - 1) = 1;
    }
  }
  if (s.at(0) == '0') j = 1;
  if (j == 0) {
    for (int(i) = 0; (i) < (n); (i)++) {
      cout << s.at(i);
    }
  } else {
    cout << -1 << endl;
  }
}
