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