#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int si, c;
  vector<int> s(n, 0);
  vector<bool> already(n, false);
  for (int i = 0; i < m; i++) {
    cin >> si >> c;
    if (already[si - 1] == true && s[si - 1] != c) {
      cout << "-1" << endl;
      exit(0);
    }
    already[si - 1] = true;
    if (si == 1 && c == 0) {
      cout << "-1" << endl;
      exit(0);
    }
    s[si - 1] = c;
  }
  if (s[0] == 0) s[0] = 1;
  if (n == 1) {
    cout << s[0] << endl;
  } else if (n == 2) {
    cout << s[0] * 10 + s[1] << endl;
  } else if (n == 3) {
    cout << s[0] * 100 + s[1] * 10 + s[2] << endl;
  }
}
