#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10] = {0};
  int b[10] = {0};
  int n, m;
  cin >> n >> m;
  int a1, b1;
  int temp = 0;
  for (int i = 1; i <= m; i++) {
    cin >> a1 >> b1;
    if (a1 == 1 && b1 == 0) {
      temp = 1;
      continue;
    }
    if (b[a1] == b1) {
      continue;
    }
    if (b[a1] == 0) {
      b[a1] = b1;
      continue;
    }
    if (b[a1] != b1) temp = 1;
  }
  if (b[1] == 0) b[1] = 1;
  if (temp == 1) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      cout << b[i];
    }
  }
}
