#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[10];
int main() {
  cin >> n >> m;
  bool p = true;
  for (int i = 0; i < m; i++) {
    int h, g;
    cin >> h >> g;
    if (h == 1 && g == 0) p = false;
    if (a[h] == 0) {
      a[h] = g;
    } else {
      if (a[h] != g) p = false;
    }
  }
  if (a[1] == 0 && p == true) a[1] = 1;
  if (p) {
    for (int i = 1; i <= n; i++) cout << a[i];
  } else {
    cout << -1;
  }
}
