#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<char> s(n, '0');
  vector<bool> vis(n, 0);
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    char c;
    cin >> c;
    x = n - x;
    if (vis[x] && s[x] != c) {
      cout << -1 << endl;
      return 0;
    }
    s[x] = c;
    vis[x] = true;
  }
  if (s[n - 1] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}
