#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] = {'a', 'a', 'a', 'a', 'a'};
  bool No = false;
  for (int i = 0; i < m; i++) {
    int x;
    char y;
    cin >> x >> y;
    if (val[x] == 'a') {
      if (y != '0')
        val[x] = y;
      else
        val[x] = '#';
    } else {
      if (val[x] != y) {
        No = true;
      } else {
        val[x] = y;
      }
    }
  }
  if (No) {
    cout << -1;
  } else {
    if (val[1] == '#') {
      cout << -1;
    } else {
      for (int i = 1; i <= n; i++) {
        if (val[i] == '#' || val[i] == 'a') {
          cout << 0;
        } else {
          cout << val[i];
        }
      }
    }
  }
}
