#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int max_n = (int)pow(10, n);
  int s[100], c[100];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if ((n + 1 - s[i]) == n && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans = 0;
  for (; ans < max_n; ans++) {
    int x = 0;
    for (x = 0; x < m; x++) {
      int ten = (int)pow(10, (n + 1 - s[x]) - 1);
      int val = ans / ten % 10;
      if (val != c[x]) {
        break;
      }
    }
    if (x == m) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
