#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int digits(long long int n) {
  int res = 0;
  while (n > 0) {
    n /= 10;
    res++;
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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 = 0; i < (1000); ++i) {
    if (digits(i) != n) continue;
    bool ok = true;
    string t = to_string(i);
    for (int j = 0; j < (m); ++j) {
      if (t[s[j] - 1] != c[j]) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
