#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int m = 0;
  cin >> n >> m;
  int s[m];
  int c[m];
  int check = 0;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> sum;
  int b = 0;
  int d = 0;
  if (n == 1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] == 0) {
        check++;
      } else {
        d++;
      }
    }
    if (check != 0 && d == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    b = i;
    for (int k = 0; k < n; k++) {
      sum.push_back(b % 10);
      b /= 10;
    }
    reverse(sum.begin(), sum.end());
    for (int j = 0; j < m; j++) {
      if (sum[s[j] - 1] == c[j]) {
        check++;
      }
    }
    if (check == m) {
      cout << i << endl;
      return 0;
    }
    check = 0;
  }
  cout << "-1" << endl;
  return 0;
}
