#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
}
const ll INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  for (int i = 0; i < (int)m; i++) cin >> sc[i].first >> sc[i].second;
  int max_v = 1000;
  bool flag = false;
  string tmp;
  for (int i = 0; i < max_v; i++) {
    tmp = to_string(i);
    if (tmp.length() != n) continue;
    for (int j = 0; j < m; j++) {
      if (tmp[sc[j].first - 1] == sc[j].second)
        flag = true;
      else
        flag = false;
      if (!flag) break;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
