#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M, ans;
  scanf("%d %d", &N, &M);
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &s.at(i), &c.at(i));
  }
  int MaxNum = pow(10, N);
  int MinNum = pow(10, N - 1);
  if (N == 1) MinNum = 0;
  ans = -1;
  for (int i = MinNum; i < MaxNum; i++) {
    string NumChar = to_string(i);
    for (int j = 0; j < M; j++) {
      if (NumChar.size() >= s.at(j)) {
        if (NumChar.at(s.at(j) - 1) - '0' == c.at(j)) {
          if (j == M - 1) {
            ans = i;
            printf("%d\n", ans);
            return 0;
          } else {
            continue;
          }
        } else
          break;
      } else
        break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
