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