#include <bits/stdc++.h>
using namespace std;
int main() {
  bool check = 1;
  int i = 0;
  int num[11][2];
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> num[i][0] >> num[i][1];
  }
  i = 0;
  while (check == 1) {
    bool kaku = 1;
    string S = to_string(i);
    if (S.size() < N) {
      i++;
      continue;
    }
    for (int j = 0; j < M; j++) {
      if (S.at(num[j][0] - 1) != num[j][1]) kaku = 0;
    }
    if (kaku == 1) {
      cout << i << endl;
      break;
    } else if (S.size() > N) {
      cout << -1 << endl;
      break;
    } else
      i++;
  }
}
