#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool ans = true;
  cin >> n;
  cin >> m;
  int s[m];
  int c[m];
  int num[3] = {-1, -1, -1};
  for (int ii1 = 0; ii1 < m; ii1++) {
    cin >> s[ii1];
    cin >> c[ii1];
  }
  for (int ii1 = 0; ii1 < m; ii1++) {
    if (s[ii1] == 1) {
      if (c[ii1] == 0) {
        ans = false;
        break;
      }
    }
    if (num[s[ii1] - 1] != -1) {
      if (c[ii1] != num[s[ii1] - 1]) {
        ans = false;
        break;
      }
    }
    num[s[ii1] - 1] = c[ii1];
  }
  if (num[0] == -1) num[0] = 1;
  for (int ii1 = 1; ii1 < n; ii1++) {
    if (num[ii1] == -1) num[ii1] = 0;
  }
  if (ans) {
    for (int ii1 = 0; ii1 < n; ii1++) {
      cout << num[ii1];
    }
  } else {
    cout << -1;
  }
  return 0;
}
