#include <bits/stdc++.h>
using namespace std;
int main() {
  string kq = "";
  bool test[4];
  memset(test, false, 4);
  test[0] = false;
  int m, n;
  cin >> n >> m;
  char tam;
  int a, b;
  for (int i = 1; i <= n; i++) kq += '0';
  while (m--) {
    cin >> a >> b;
    tam = char(b + '0');
    if (test[a - 1] == true && kq[a - 1] != tam) {
      cout << -1;
      return 0;
    }
    test[a - 1] = true;
    kq[a - 1] = tam;
  }
  if (kq[0] != '0')
    cout << kq;
  else
    cout << -1;
  return 0;
}
