#include <bits/stdc++.h>
using namespace std;
vector<long long int> pos[21];
long long int inp[100];
map<long long int, long long int> mp;
vector<long long int> ans;
long long int arrra[200009];
map<long long int, long long int> cnt;
vector<long long int>::iterator upper1, upper2;
int main() {
  long long int i, j, k, l, t, n, x = 0, y = 0, p, q, z = 0, a = 2, b, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> l >> p;
    if (arrra[l - 1] == 0) {
      arrra[l - 1] = p;
    } else {
      if (arrra[l - 1] != p) x = -1;
    }
  }
  if (x == -1) {
    cout << "-1";
    return 0;
  } else {
    for (i = 0; i < n; i++) {
      if (arrra[i] == 0 && y == 0) continue;
      y = 1;
      cout << arrra[i];
    }
    if (y == 0) cout << "-1";
  }
}
