#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, x;
  char c;
  cin >> N >> M;
  vector<char> t(N, '0');
  string r = "", r2;
  set<int> y;
  for (int i = 0; i < (M); ++i) {
    cin >> s >> c;
    if (y.count(s) && t.at(s - 1) != c) {
      cout << -1 << endl;
      return 0;
    }
    y.insert(s);
    t.at(s - 1) = c;
  }
  for (int i = 0; i < (N); ++i) r += t.at(i);
  if (r.at(0) == '0') r.at(0) = '1';
  cout << r << endl;
}
