#include <bits/stdc++.h>
using namespace std;
const int MAX = 10;
int N, M;
int S[MAX], C[MAX];
int pow(int n, int k) {
  int ret = 1;
  for (long long i = 0; i < k; ++i) ret *= n;
  return ret;
}
long long sub() {
  if (N == 1) return 0;
  if (N == 2)
    return 10;
  else
    return 100;
}
long long solve() {
  if (M == 0) return sub();
  if (N == 1) {
    for (long long i = 0; i < 10; ++i) {
      for (long long m = 0; m < M; ++m) {
        if (C[m] != i) continue;
      }
      return i;
    }
    return -1;
  }
  vector<long long> num(N, -1);
  for (long long i = 0; i < M; ++i) {
    long long s = S[i] - 1;
    if (num[s] != -1 && num[s] != C[i]) return -1;
    num[s] = C[i];
    if (s == 0 && C[i] == 0) return -1;
  }
  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    int n = num[i];
    long long x = n;
    if (n == -1) {
      if (i == 0) {
        if (N == 1)
          x = 0;
        else
          x = 1;
      } else
        x = 0;
    }
    ans = ans * 10 + x;
  }
  if (N != 1 && ans == 0) {
    ans = 1;
    for (long long i = 0; i < N - 1; ++i) ans *= 10;
  }
  return ans;
}
int main() {
  cin >> N >> M;
  for (long long i = 0; i < M; ++i) cin >> S[i] >> C[i];
  cout << solve() << endl;
}
