#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> S;
  for (int i = 0; i < (int)(M); i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    S.push_back(make_pair(s, c));
  }
  int ans = -1;
  for (int i = 0; i < (int)(1000); i++) {
    int flag = 1;
    string num = to_string(i);
    for (auto s : S) {
      if (num[s.first] != s.second || num.size() - 1 < s.first) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
