#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> data;
  for (int m = 0; m < M; m++) {
    int s, c;
    cin >> s >> c;
    data[s] = c;
  }
  for (int n = 0; n < pow(10, N + 1); n++) {
    string num = std::to_string(n);
    bool match = true;
    for (int i = 1; i < N + 1; i++) {
      if (data.count(i) && data[i] != ((int)num[i - 1] - '0')) {
        match = false;
      }
    }
    if (match) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
