#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, i, j, k, s[20005], c[20005];
  cin >> n >> m;
  for (long long int i = 0; i <= m - 1; i++) cin >> s[i] >> c[i];
  for (long long int i = pow(10, n - 1); i <= (pow(10, n) - 1); i++) {
    long long int chck = 0;
    long long int x[3];
    x[2] = i % 10;
    x[1] = ((i / 10) % 10);
    x[0] = ((i / 100) % 10);
    for (long long int j = 0; j <= m - 1; j++) {
      chck += (x[(s[j] - n + 2)] != c[j]);
      chck += (s[j] == 1 && c[j] == 0);
    }
    if (!chck) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
