#include <bits/stdc++.h>
using namespace std;
map<int, int> marked;
vector<vector<int>> Sheet;
string s;
bool satisfy(vector<pair<int, char>> conditions, int n) {
  s = to_string(n);
  for (auto condition : conditions) {
    if (s[condition.first - 1] != condition.second) return false;
  }
  return true;
}
int main() {
  int n, m;
  int num = -1;
  cin >> n >> m;
  int in1;
  char in2;
  vector<pair<int, char>> conditions;
  for (int i = 0; i < m; i++) {
    cin >> in1 >> in2;
    conditions.push_back(make_pair(in1, in2));
  }
  int limit = pow(10, n);
  for (int i = 0; i < limit; i++) {
    if (satisfy(conditions, i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
