#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, flag = 0;
  cin >> a >> b;
  vector<long long> v(a, 0);
  v[0] = 1;
  for (int i = 0; i < b; i++) {
    cin >> c >> d;
    if (v[c - 1] != 0 && i != 0 && d != v[c - 1]) {
      flag = 1;
    } else {
      v[c - 1] = d;
    }
  }
  if (flag == 1 || (a > 1 && v[0] == 0)) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < a; i++) {
      cout << v[i];
    }
    cout << endl;
  }
}
