#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  string num(N, '0');
  if (N > 1) num[0] = '1';
  int start = stoi(num);
  num = num + '0';
  int end = stoi(num);
  for (int i = start; i < end; i++) {
    bool check = true;
    string x = to_string(i);
    for (int j = 0; j < M; j++) {
      if (x[s[j] - 1] != c[j] + '0') {
        check = false;
        break;
      }
    }
    if (check == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
