#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> C(N);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }
  for (int i = 0; i < int(1000); i++) {
    string str_num = to_string(i);
    if (str_num.length() != N) continue;
    bool flg = true;
    for (int j = 0; j < int(M); j++) {
      if (str_num[S.at(j) - 1] != C.at(j) + '0') {
        flg = false;
      }
    }
    if (flg) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
