#include <bits/stdc++.h>
using namespace std;
int check(int N, int p) {
  if (p == 3)
    return N / 100;
  else if (p == 2)
    return (N / 10) % 10;
  else if (p == 1)
    return N % 10;
}
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> a(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> a[i][0];
    cin >> a[i][1];
  }
  int b = 1;
  for (int i = 1; i < N; i++) {
    b *= 10;
  }
  int e = b * 10;
  bool exist = false;
  for (int i = b; i < e; i++) {
    bool c = true;
    for (int j = 0; j < M; j++) {
      if (check(i, N + 1 - a[j][0]) != a[j][1]) c = false;
    }
    if (c) {
      cout << i << endl;
      exist = true;
      break;
    }
  }
  if (!exist) cout << -1 << endl;
  return 0;
}
