#include <bits/stdc++.h>
using namespace std;
int n, m;
int first, b;
int a[4];
int main(void) {
  cin >> n >> m;
  bool vis = true;
  while (m--) {
    cin >> first >> b;
    if (vis == false) continue;
    if (n > 1 && first == 1 && b == 0) {
      vis = false;
    } else if (a[first] != 0 && a[first] != b) {
      vis = false;
    } else {
      a[first] = b;
    }
  }
  if (vis == false) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}
