#include <bits/stdc++.h>
using namespace std;
int s[5], c[5];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  bool ans0 = true;
  for (int i = 0; i < M; i++) {
    if (s[i] != 1 || c[i] != 0) ans0 = false;
  }
  if (ans0) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 1; i <= 999; ++i) {
    int d = 0;
    int temp = i;
    bool check = true;
    while (temp > 0) {
      d++;
      temp /= 10;
    }
    if (d != N) continue;
    for (int j = 0; j < M; j++) {
      temp = i;
      for (int i = 0; i < N - s[j]; i++) {
        temp /= 10;
      }
      temp = temp % 10;
      if (c[j] != temp) check = false;
    }
    if (check) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
  return 0;
}
