#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4] = {0};
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a[s] != 0) {
      if (a[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      a[s] = c;
    }
  }
  if (a[1] == 0 && N != 1) {
    a[1] = 1;
  }
  for (int i = 1; i <= N; i++) {
    cout << a[i];
  }
  cout << endl;
  return 0;
}
