#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  a[1] = a[2] = a[3] = -1;
  bool flag = false;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (a[x] != -1 && a[x] != y) {
      flag = true;
      break;
    }
    a[x] = y;
  }
  if (a[1] == 0 || flag) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1 && i == 1) {
      cout << "1";
      continue;
    }
    if (a[i] == -1)
      cout << "0";
    else
      cout << a[i];
  }
}
