#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int i, j;
  int s[M], c[M];
  for (i = 0; i < M; i++) cin >> s[i] >> c[i];
  int n, count;
  int num[3];
  for (i = 0; i < 1000; i++) {
    count = 0;
    num[0] = 0;
    num[1] = 0;
    num[2] = 0;
    n = i;
    while (n != 0) {
      num[2 - count] = n % 10;
      n /= 10;
      count++;
    }
    if (count == N) {
      if (num[0] == 0) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = 0;
      }
      if (num[0] == 0) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = 0;
      }
      for (j = 0; j < M; j++) {
        if (num[s[j] - 1] != c[j]) break;
      }
      if (j == M) {
        for (int k = 0; k < 3; k++)
          if (num[k] != 0) cout << num[k];
        cout << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
