#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool exist = true;
  int sc[m][3];
  for (int i = 0; i < m; i++) {
    cin >> sc[i][0] >> sc[i][1];
    if (sc[i][0] == 1 && sc[i][1] == 0) {
      exist = false;
    }
  }
  if (!exist) {
    cout << -1 << endl;
    return 0;
  }
  int ans = -1;
  int max_i = pow(10, m) - 1;
  int min_i = pow(10, m - 1);
  for (int i = min_i; i < max_i; i++) {
    bool tmp_exit = true;
    for (int j = 0; j < m; j++) {
      int x = (i / (int)pow(10, m - sc[j][0])) % 10;
      if (x != sc[j][1]) {
        tmp_exit = false;
      }
    }
    if (tmp_exit) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
