#include <bits/stdc++.h>
using namespace std;
void arr_int(int* given_arr, int n) {
  for (int i = 0; i < n; i++) scanf("%d", &given_arr[i]);
  return;
}
void solve();
int main(int argc, char const* argv[]) {
  solve();
  return 0;
}
void solve() {
  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);
  pair<int, int> q[M];
  for (int i = 0; i < M; i++) scanf("%d %d", &q[i].first, &q[i].second);
  int l = 1;
  for (int i = 1; i < N; i++) l *= 10;
  for (int t = l; t < 10 * l; t++) {
    bool done = true;
    for (int j = 0; j < M; j++) {
      int set<int> = N - (q[j].first);
      int ci = q[j].second;
      int temp = t;
      while (set<int>) {
        temp /= 10;
        set<int> --;
      }
      if (temp % 10 != ci) {
        done = false;
        break;
      }
    }
    if (done) {
      printf("%d\n", t);
      return;
    }
  }
  printf("%d\n", -1);
}
