#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> d(N, -1);
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int at, dig;
    cin >> at >> dig;
    at--;
    if (at + 1 > N || d[at] >= 0 && d[at] != dig) {
      cout << -1 << endl;
      return 0;
    }
    d[at] = dig;
  }
  if (d[0] == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  }
  if (d[0] < 0) {
    d[0] == (N == 1) ? 0 : 1;
  }
  for (int i = 0; i < N; i++) {
    cout << max(d[i], 0);
  }
  cout << endl;
  return 0;
}
