#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    sc.push_back({s, c});
  }
  const int mins[] = {0, 0, 10, 100};
  int min = mins[N];
  const int maxs[] = {0, 9, 99, 999};
  int max = maxs[N];
  for (int i = min; i <= max; i++) {
    bool legit = true;
    for (auto sc : sc) {
      int si = sc.first;
      int ci = sc.second;
      int candidate = i;
      for (int k = 0; k < N - si; k++) {
        candidate /= 10;
      }
      candidate %= 10;
      if (ci != candidate) {
        legit = false;
        break;
      }
    }
    if (legit) {
      cout << i << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
  return 0;
}
