#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  string s;
  cin >> n >> m;
  s.resize(n, '0');
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    s[a - 1] = b + '0';
  }
  int p = 0;
  stringstream ss(s);
  ss >> p;
  int k = log10((double)p) + 1;
  if (k == n)
    cout << p;
  else
    cout << "-1";
  return 0;
}
