#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> vs;
  vector<char> vc;
  string res = string(n, '0');
  for (int i = 0; i < (m); ++i) {
    int s;
    cin >> s;
    vs.push_back(s);
    char c;
    cin >> c;
    vc.push_back(c);
    res[s - 1] = c;
  }
  for (int i = 0; i < (m); ++i) {
    int s = vs[i];
    char c = vc[i];
    if (res[s - 1] != c) {
      cout << -1;
      return 0;
    }
  }
  if (res.length() > 1 and res[0] == '0') {
    cout << -1;
  } else {
    cout << res;
  }
  return 0;
}
