#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[10], s, c;
  map<int, int> q;
  cin >> n >> m;
  int flag = 1;
  memset(a, 0, sizeof(a));
  while (m--) {
    cin >> s >> c;
    if (q[s] == 0) {
      q[s] = c;
      a[s] = c;
    } else {
      if (q[s] != c) flag = 0;
    }
  }
  if (a[1] == 0 && n > 1) flag = 0;
  if (flag == 0)
    puts("-1");
  else {
    for (int i = 1; i <= n; i++) cout << a[i];
  }
  return 0;
}
