#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  long long n, m, mxs = 0;
  cin >> n >> m;
  vector<long long> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++)
    cin >> s[i] >> c[i], s[i]--, mxs = max(mxs, s[i]);
  for (long long i = (long long)pow(10ll, n - 1); i <= (long long)pow(10ll, n);
       ++i) {
    string S = to_string(i);
    bool ok = true;
    for (int j = 0; j < (S.size()); j++)
      if (S[s[j]] != c[j]) ok = false;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}
