#include <bits/stdc++.h>
using namespace std;
int n, q, flag = 1;
int a[3];
signed main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) a[i] = -1;
  for (int i = 1; i <= q; i++) {
    int rt, num;
    cin >> rt >> num;
    if (a[rt] == num || a[rt] == -1)
      a[rt] = num;
    else
      flag = 0;
  }
  if (flag == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0) {
      flag = 0;
      break;
    }
    if (flag == 1 && a[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  flag = 0;
  if (a[1] == -1) a[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
  return 0;
}
