#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[6], c[6];
  for (int i(0); i < m; i++) {
    cin >> s[i] >> c[i];
  }
  bool flag(true);
  for (int i(0); i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      flag = false;
    }
  }
  for (int i(0); i < m - 1; i++) {
    for (int j(i + 1); j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        flag = false;
      }
    }
  }
  if (flag) {
    int answer[4];
    for (int i(0); i < n; i++) {
      answer[i] = 0;
    }
    for (int i(0); i < m; i++) {
      answer[s[i] - 1] = c[i];
    }
    for (int i(0); i < n; i++) {
      if (i == 0 && answer[i] == 0) {
        cout << 1;
      } else {
        cout << answer[i];
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
