#include <bits/stdc++.h>
using namespace std;
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];
  }
  for (int iNum = 0; iNum < 1000; iNum++) {
    int count = 0;
    for (int i = 0; i < M; i++) {
      int k = pow(10, 3 - s[i]);
      if (((iNum % (k * 10)) / k) == c[i]) {
        count++;
      }
    }
    if (count == M) {
      if (iNum == 0) {
        cout << -1;
        return 0;
      }
      cout << iNum;
      return 0;
    } else {
      count = 0;
    }
  }
  cout << -1;
  return 0;
}
