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