#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e18;
const long long dx4[4] = {1, 0, -1, 0};
const long long dy4[4] = {0, 1, 0, -1};
const long long dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const double pi = acos(-1);
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using Graph = vector<vector<long long>>;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
  std::ifstream in("sample.txt");
  std::cin.rdbuf(in.rdbuf());
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  string ans = "???";
  for (long long i = 0; i < m; i++) {
    long long s;
    cin >> s;
    s--;
    char c;
    cin >> c;
    if (ans[s] == '?')
      ans[s] = c;
    else
      ans = ((ans[s] == c) ? ans : "-1");
  }
  if (ans[0] == '0') ans = "-1";
  if (ans[0] == '?') ans[0] = '1';
  if (ans[1] == '?') ans[1] = '1';
  if (ans[2] == '?') ans[2] = '1';
  cout << ans << endl;
}
signed main() {
  solve();
  return 0;
}
