#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cins(vector<T>& arr) {
  for (T& e : arr) cin >> e;
}
int power10(int num) {
  int ans = 1;
  while (num--) {
    ans *= 10;
  }
  return ans;
}
int main(void) {
  int num, qs;
  cin >> num >> qs;
  vector<pair<int, int> > queries(qs);
  for (int i = 0; i < qs; i++) {
    int s, c;
    cin >> s >> c;
    queries[i] = make_pair(s, c);
  }
  int ans = -1;
  for (int n = power10(num - 1); n < power10(num); n++) {
    int flag = 1;
    for (int k = 0; k < qs; k++) {
      int val = n;
      pair<int, int> q = queries[k];
      int s = num + 1 - q.first;
      while (--s) {
        val /= 10;
      }
      val %= 10;
      if (val != q.second) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans = n;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
