#include <bits/stdc++.h>
using namespace std;
void yes() { cout << "yes" << endl; }
void Yes() { cout << "Yes" << endl; }
void YES() { cout << "YES" << endl; }
void no() { cout << "no" << endl; }
void No() { cout << "No" << endl; }
void NO() { cout << "NO" << endl; }
long long INF = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int start, end;
  if (N == 1) {
    start = 0;
    end = 9;
  } else if (N == 2) {
    start = 10;
    end = 99;
  } else {
    start = 100;
    end = 999;
  }
  for (int n = start; n <= end; n++) {
    bool flag = true;
    int tmp;
    for (int i = 0; i < M; i++) {
      tmp = n;
      for (int j = 0; j < N - s[i]; j++) tmp /= 10;
      flag = flag * (tmp % 100 == c[i]);
    }
    if (flag) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
