#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int max = -1;
  int start = 0;
  if (N == 1) start = 1;
  if (N == 2) start = 10;
  if (N == 3) start = 100;
  for (int i = start; i < start * 10; i++) {
    bool l = true;
    for (int j = 0; j < M; j++) {
      int div = 0;
      if (s.at(j) == 1) div = 100;
      if (s.at(j) == 2) div = 10;
      if (s.at(j) == 3) div = 1;
      int num = i / div;
      num %= div * 10;
      int ans = c.at(j);
      if (num != ans) {
        l = false;
      }
    }
    if (l) {
      max = i;
      break;
    }
  }
  cout << max << endl;
}
