#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, flg = 0, a[1000];
  cin >> n >> m;
  if (n == 1 && !m) {
    cout << 0 << endl;
    return 0;
  }
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (n != 1 && x == 1 && y == 0) {
      flg = 1;
    } else if (a[x] == -1) {
      a[x] = y;
    } else {
      if (flg == a[x])
        flg = 0;
      else
        flg = 1;
    }
  }
  if (flg) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && i == 1) {
      cout << 1;
      continue;
    } else if (a[i] == -1) {
      cout << 0;
      continue;
    }
    cout << a[i];
  }
  return 0;
}
