#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>>(X);
  ;
  for (int x = 0; x < (M); x++) {
    int aa, bb;
    cin >> aa >> bb;
    (X).push_back(make_pair(aa, bb));
    ;
  }
  for (int x = 0; x < (1000); x++) {
    int a[3] = {-1, -1, -1};
    int y = x;
    int z = 0;
    while (y > 0) {
      a[z++] = y % 10;
      y /= 10;
    }
    bool flag = true;
    for (int z = 0; z < (M); z++) {
      if (a[N - X[z].first] != X[z].second) {
        flag = false;
      }
    }
    if (flag) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
