#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, i;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  string Suuji;
  for (i = 0; i < 1001; i++) {
    bool flag = 0;
    Suuji = to_string(i);
    if (Suuji.size() != N) continue;
    if (Suuji.size() < M) continue;
    for (int j = 0; j < M; j++) {
      if (Suuji.at(s.at(j) - 1) != to_string(c.at(j)).at(0)) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
