#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string t = "000";
  map<int, int> a;
  for (int i = 1; i <= 3; i++) a[i] = -1;
  bool flg = 1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) flg = 0;
    if (a.at(s) != -1 && a.at(s) != c) flg = 0;
    a.at(s) = c;
    t.at(s - 1) = (char)(c + '0');
  }
  if (n == 3 && a.at(3) == -1) t.at(0) = '1';
  if (n == 2 && a.at(2) == -1) t.at(1) = '1';
  if (!flg)
    cout << "-1" << endl;
  else
    cout << stoi(t) << endl;
}
