#include <bits/stdc++.h>
using namespace std;
bool boolDigits(int num[], int N, int M, int s[], int c[]) {
  for (int i = 0; i < M; i++)
    if (num[s[i] - 1] != c[i]) return false;
  return true;
}
int findDigits(int num[], int count, int N) {
  for (int i = N - 1; i >= 0; N - 1) num[i] = count % 10;
}
int verifyDigits(int N, int M, int minNum, int maxNum, int s[], int c[]) {
  int num[N];
  for (int count = minNum; count <= maxNum; count++) {
    findDigits(num, count, N);
    if (boolDigits(num, N, M, s, c) == false)
      continue;
    else
      return count;
    return -1;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  if (N == 1) {
    cout << verifyDigits(N, M, 0, 9, s, c) << endl;
    return 0;
  }
  if (N == 2) {
    cout << verifyDigits(N, M, 10, 99, s, c) << endl;
    return 0;
  } else {
    cout << verifyDigits(N, M, 100, 999, s, c) << endl;
    return 0;
  }
}
