#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, tmp1, tmp2;
  cin >> n >> m;
  vector<int> data(n);
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> tmp1 >> tmp2;
    if (tmp1 > n) {
      cout << -1 << endl;
      return 0;
    }
    if (tmp2 == 0) {
      if (tmp1 != n) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (data.at(tmp1 - 1) != 0 && data.at(tmp1 - 1) != tmp2) {
      cout << -1 << endl;
      return 0;
    }
    data.at(tmp1 - 1) = tmp2;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0 && data.at(i) == 0) {
      data.at(i) = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << data.at(i);
  }
}
