#include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < (int)M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  int count_correct;
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    count_correct = 0;
    for (int j = 0; j < (int)M; j++) {
      int k = floor(i / pow(10, (N - s[j])));
      if (k % 10 == c[j]) {
        count_correct++;
      }
    }
    if (count_correct == M) ans = i;
    if (ans != -1) break;
  }
  cout << ans;
}
