#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
template <class T>
void show(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << endl;
}
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 main(int argc, char const* argv[]) {
  int n, m;
  cin >> n >> m;
  vector<char> c(m);
  vector<int> s(m);
  int ans = -1;
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  for (int i = 1000; i >= 0; i--) {
    string S = to_string(i);
    bool ok = true;
    if (((int)(s).size()) != n) ok = false;
    for (int j = 0; j < (m); j++)
      if (S[s[j] - 1] != (char)(c[j] + '0')) ok = false;
    if (ok) ans = i;
  }
  cout << ans << endl;
  return 0;
}
