#include <bits/stdc++.h>
using namespace std;
int check(int x) {
  if (x == 0) return 1;
  int num = 0;
  while (x) {
    num++;
    x /= 10;
  }
  return num;
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<int> a(N);
  for (unsigned int i = 0; i < N; i++) a[i] = -1;
  for (unsigned int i = 0; i < s.size(); i++) {
    if (a[s[i] - 1] == -1)
      a[s[i] - 1] = c[i];
    else if (a[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return;
    }
  }
  int num = 0;
  for (unsigned int i = 0; i < N; i++) {
    if (a[i] == -1)
      num = num * 10;
    else
      num = num * 10 + a[i];
  }
  if (check(num) == N)
    cout << num << endl;
  else
    cout << -1 << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
