#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> c(m);
  vector<int> s(m);
  for (int i = 0, i_len = (m); i < i_len; ++i) cin >> s[i] >> c[i];
  int num;
  if (n == 1)
    num = 10;
  else if (n == 2)
    num = 100;
  else
    num = 1000;
  bool t = true;
  int ans;
  for (int i = 0, i_len = (num); i < i_len; ++i) {
    string x = to_string(i);
    t = true;
    for (int j = 0, j_len = (m); j < j_len; ++j) {
      if (x[s[j] - 1] != c[j]) {
        t = false;
        break;
      }
    }
    if (t) {
      ans = i;
      break;
    }
  }
  if (t)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
