#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 100; i < 1000; ++i) {
    bool elf = true;
    string t = to_string(i);
    for (int i = 0; i < (m); ++i) {
      int a = s[i] - 1;
      if (t[a] != c[i]) elf = false;
    }
    if (elf) {
      cout << i << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
  return 0;
}
