#include <bits/stdc++.h>
using namespace std;
const int MAX = 10;
int N, M;
int S[MAX], C[MAX];
long long solve() {
  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 (const auto& n : num) {
    long long x = n;
    if (n == -1) 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;
}
