#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long MOD = 1e9 + 7;
const int INF = 1e5;
int pow(int t, int n) {
  int ret = 1;
  for (int i = 0; i < n; i++) ret *= t;
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    S[i] = s;
    C[i] = c;
  }
  int ans = INF;
  for (int x = int(pow(10, N - 1)); x < int(pow(10, N)); x++) {
    bool valid = true;
    vector<int> X(N);
    int y = x;
    for (int i = 0; i < N; i++) {
      X[i] = y % 10;
      y /= 10;
    }
    reverse(X.begin(), X.end());
    for (int i = 0; i < M; i++) {
      int s, c;
      s = S[i];
      c = C[i];
      if (c != X[s - 1]) valid = false;
      if (N != 1 && s == 1 && c == 0) valid = false;
    }
    if (valid) {
      chmin(ans, x);
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
