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