#include <bits/stdc++.h>
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solve() {
  int N, M;
  cin >> N >> M;
  string str(N, '0');
  str[0] = '1';
  if (N == 1) str[0] = '0';
  for (int i = 1; i < N; ++i) {
    str[i] = '0';
  }
  bool same_idx[3];
  for (int i = 0; i < (3); ++i) same_idx[i] = false;
  for (int i = 0; i < (M); ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (s == 1) {
      if (same_idx[0] && (str[0] != c)) {
        cout << "-1"
             << "\n";
        return;
      } else {
        str[0] = c;
        same_idx[0] = true;
      }
    }
    if (s == 2) {
      if (same_idx[1] && (str[1] != c)) {
        cout << "-1"
             << "\n";
        return;
      } else {
        str[1] = c;
        same_idx[1] = true;
      }
    }
    if (s == 3) {
      if (same_idx[2] && (str[2] != c)) {
        cout << "-1"
             << "\n";
        return;
      } else {
        str[2] = c;
        same_idx[2] = true;
      }
    }
  }
  int ans = stoi(str);
  if ((pow(10, (N - 1)) <= ans) && (ans <= (pow(10, N) - 1))) {
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
