#include <bits/stdc++.h>
using namespace std;
long long ty, n, m, f[200005], ww, a[20005], b[20005], a1;
vector<long long> v;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    f[i] = -1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    if (f[a[i]] == -1) {
      f[a[i]] = b[i];
      continue;
    }
    if (f[a[i]] != -1 && f[a[i]] != b[i]) {
      ww = 1;
      continue;
    }
    if (f[a[i]] != -1 && f[a[i]] == b[i]) {
      f[a[i]] = b[i];
      continue;
    }
  }
  if (ww == 1 || f[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1) {
    if (f[1] != -1)
      cout << f[1] << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= 1000; i++) {
    ty = 0;
    v.clear();
    a1 = i;
    while (a1 > 0) {
      v.push_back(a1 % 10);
      a1 /= 10;
    }
    if (v.size() > n) continue;
    if (v.size() < n) continue;
    for (int i = 0; i < v.size(); i++) {
      for (int j = 1; j <= m; j++) {
        if (v[a[j] - 1] != b[j]) {
          ty = 1;
        }
      }
    }
    if (ty == 0) {
      for (int j = 0; j < v.size(); j++) {
        cout << v[j];
      }
      return 0;
    }
  }
}
