#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m + 5];
  char c[m + 5];
  string a = "";
  for (int i = 0; i < n; i++) a += 'a';
  for (int i = 0; i < m; i++) {
    int x;
    char y;
    cin >> x >> y;
    x--;
    s[i] = x;
    c[i] = y;
    if (a[x] == 'a')
      a[x] = y;
    else {
      if (a[x] != y) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (a[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (a[0] == 'a') {
    if (n != 1)
      a[0] = '1';
    else
      a[0] = '0';
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 'a')
      cout << 0;
    else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
