#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  bool ans = true;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) ans = false;
    if (A[s - 1] != 0) {
      if (A[s - 1] != c) ans = false;
    }
    A[s - 1] = c;
  }
  if (!(ans)) {
    cout << -1 << endl;
    return 0;
  }
  if (A[0] == 0) A[0] = 1;
  for (int i = 0; i < (int)(n); i++) cout << A[i];
  cout << endl;
  return 0;
}
