#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<char> ans(n, 'a');
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (ans[s - 1] == 'a') {
      ans[s - 1] = c;
    } else if (c != ans[s - 1]) {
      ok = false;
    }
  }
  if (!ok)
    cout << -1 << endl;
  else if (n == 1) {
    if (ans[0] == 'a')
      cout << 0 << endl;
    else
      cout << ans[0] << endl;
  } else {
    if (ans[0] == '0' || !ok)
      cout << -1 << endl;
    else {
      for (int i = 0; i < n; i++) {
        if (ans[i] == 'a')
          cout << 0;
        else
          cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}
