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