#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> scan(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    scan.at(i) = make_pair(s, c);
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string num = to_string(i);
    bool judge = false;
    for (int j = 0; j < M; j++) {
      int s = scan.at(j).first;
      char c = char(scan.at(j).second) + '0';
      if (num.at(s) != c) judge = true;
      if (judge) break;
    }
    if (judge) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
}
