#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> v[2];
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    v[0].push_back(s);
    v[1].push_back(c);
  }
  for (int i = pow(10, N - 1); i <= 999; i++) {
    bool false_flag = 0;
    for (int j = 0; j < M; j++) {
      string i_str = to_string(i);
      int digits = v[0][j] - 1;
      char value = v[1][j] + '0';
      if (i_str[digits] != value) {
        false_flag = 1;
        break;
      }
    }
    if (false_flag == 1) {
      continue;
    } else {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
