#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  char val[5 + 1] = {'a', 'a', 'a', 'a', 'a'};
  bool t = false;
  int zero = 0;
  for (int i = 1; i <= m; i++) {
    int x;
    char y;
    cin >> x >> y;
    if (val[x] == 'a') {
      val[x] = y;
    } else {
      if (val[x] != y) {
        t = true;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (val[i] == '0') zero++;
  }
  if (t || (val[1] == '0' && zero != n)) {
    cout << -1;
  } else {
    if (val[1] == 'a') {
      val[1] = '1';
    }
    for (int i = 1; i <= n; i++) {
      if (val[i] != 'a')
        cout << val[i];
      else
        cout << 0;
    }
  }
}
