#include <bits/stdc++.h>
using namespace std;
int n, m;
bool check(int num, int bits, unordered_map<int, int>& rules) {
  string temp = to_string(num);
  for (auto it = rules.begin(); it != rules.end(); it++) {
    if (temp[it->first - 1] != it->second + '0') return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  int low = pow(10, n - 1);
  int hi = pow(10, n);
  unordered_map<int, int> rules;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (rules.count(s) && rules[s] != c) {
      cout << -1 << endl;
      return 0;
    } else {
      rules[s] = c;
    }
  }
  for (int i = low; i < hi; i++) {
    if (check(i, n, rules)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
