#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int M;
  cin >> N;
  cin >> M;
  int s[5];
  int c[5];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  for (int n = pow(10, N - 1) + 1; n < pow(10, N); n++) {
    bool flag = true;
    ;
    for (int j = 0; j < M; j++) {
      int temp = n;
      for (int k = 0; k < N - s[j]; k++) {
        temp /= 10;
      }
      if (temp % 10 != c[j]) flag = false;
    }
    if (flag) ans = n;
  }
  cout << ans << endl;
  return 0;
}
