#include <bits/stdc++.h>
using namespace std;
char ans[20];
int main() {
  int n, m;
  int minn, maxx;
  minn = 0x3f3f3f3f;
  maxx = -1;
  cin >> n >> m;
  fill(ans, ans + 10, '0');
  int fff = 1;
  int f = 1;
  while (m--) {
    int a;
    char b;
    cin >> a >> b;
    minn = min(a, minn);
    maxx = max(maxx, a);
    if (ans[a] != '0' && (ans[a] != b)) {
      f = 0;
      break;
    } else
      ans[a] = b;
  }
  int s = maxx - minn + 1;
  if (ans[minn] == '0') f = 0;
  if (s == n && f) {
    int ff = 0;
    for (int i = 1; i <= n; i++) {
      if (ans[i] != '0') ff = 1;
      if (ff) cout << ans[i];
    }
    if (!ff)
      cout << "0\n";
    else
      cout << "\n";
  } else
    cout << "-1\n";
  return 0;
}
