#include <bits/stdc++.h>
using namespace std;
int NdigitsEnd(int n) {
  int a = 1;
  for (int i = 0; i < n; i++) {
    a *= 10;
  }
  return a - 1;
}
int NdigitsBegin(int n) {
  int a = 1;
  for (int i = 1; i < n; i++) {
    a *= 10;
  }
  return a;
}
void assign_deque(deque<int>& d, int n) {
  if (n == 0) {
    d.push_front(0);
  }
  while (n > 0) {
    int x = n % 10;
    d.push_front(x);
    n /= 10;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  pair<int, int> digits_cond[M];
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    pair<int, int> p;
    p = make_pair(s - 1, c);
    digits_cond[i] = p;
  }
  int MIN = NdigitsBegin(N);
  int MAX = NdigitsEnd(N);
  for (int i = MIN; i <= MAX; i++) {
    bool cond = true;
    deque<int> dq;
    assign_deque(dq, i);
    for (int j = 0; j < M; j++) {
      if (dq[digits_cond[j].first] != digits_cond[j].second) {
        cond = false;
        break;
      }
    }
    if (cond) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
