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