#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
void fail() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < M; i++) cin >> S[i] >> C[i], S[i]--;
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    if (ans[S[i]] == -1 || ans[S[i]] == C[i]) {
      ans[S[i]] = C[i];
    } else {
      fail();
    }
  }
  if (ans[0] == 0) fail();
  if (ans[0] == -1) ans[0] = 1;
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) ans[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
