#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
void solve();
void in() {}
template <class T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}
void solve() {
  int N, M;
  in(N, M);
  vector<char> s(N, 0);
  for (int i = 0; i < (M); i++) {
    int si;
    char ci;
    in(si, ci);
    if (si == 1 && N != 1 && ci == '0') {
      cout << (-1) << endl;
      return;
    }
    if (s[si - 1] == 0) {
      s[si - 1] = ci;
      continue;
    }
    if (s[si - 1] == ci) {
      continue;
    }
    cout << (-1) << endl;
    return;
  }
  for (auto &x : (s)) {
    cout << (x == 0 ? '0' : x);
  }
  cout << endl;
}
