#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N + 1);
  for (int i = 1; i <= N; i++) num[i] = 10;
  num[1] = 11;
  for (int i = 1; i <= M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] > 9) {
      num[s] = c;
      continue;
    }
    if (num[s] == c)
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[1] == 0 and N == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (num[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (num[i] == 11) {
      num[i] = 1;
      continue;
    }
    if (num[i] > 9) {
      num[i] = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << num[i];
  }
  cout << endl;
  return 0;
}
