#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
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];
  vector<int> ans(N);
  for (int i = 0; i < M; ++i)
    if (s[i] == 1 && c[i] != 0) {
      ans[0] = c[i];
    } else if (s[i] == 1 && c[i] == 0 && N >= 2) {
      cout << -1 << endl;
      return 0;
    } else if (ans[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  if (ans[0] == 0 && N >= 2) ans[0] = 1;
  for (int i = 0; i < N; ++i) cout << ans[i];
  cout << endl;
  return 0;
}
