#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i = 0, s, c; cin >> s >> c; i++) V.at(i) = {s, c};
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (V.at(i).first == V.at(j).first && V.at(i).second != V.at(j).second)
        return cout << -1 << "\n", 0;
    }
  }
  for (int i = 0; i < 1000; i++) {
    string tmp = to_string(i);
    if (tmp.size() != N) continue;
    for (int j = 0; j < M; j++) {
      if (tmp.at(V.at(j).first - 1) - '0' != V.at(j).second) goto NG;
    }
    return cout << i << "\n", 0;
  NG:;
  }
}
