#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pii> sc;
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  for (int i = 0; i < pow(10, N); i++) {
    string I = to_string(i);
    int ok = 0;
    for (int j = 0; j < M; j++) {
      if (I[sc[j].first - 1] - '0' == sc[j].second) ok++;
    }
    if (ok == M) {
      cout << I << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
