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