#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using G = vector<vector<int>>;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> ans(n, -1);
  for (int i = 0; 1000; i++) {
    string num = to_string(i);
    if (num.size() != n) continue;
    bool able = true;
    for (int j = 0; j < m; j++) {
      if (num[s[j] - 1] != c[j]) able = false;
    }
    if (able) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
