#include <bits/stdc++.h>
using namespace std;
void run() {
  int n, m, i, x;
  cin >> n >> m;
  vector<int> used(n, -1);
  for (i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (used[n - s] > -1 && used[n - s] != c) {
      cout << "-1" << endl;
      return;
    }
    if (s == n && n > 1 && c == 0) {
      cout << "-1" << endl;
      return;
    }
    used[n - s] = c;
  }
  int start, end;
  if (n == 1) {
    start = 0;
    end = 9;
  } else if (n == 2) {
    start = 10;
    end = 99;
  } else {
    start = 100;
    end = 999;
  }
  if (n == 1 && used[0] >= 0) {
    cout << used[0] << endl;
    return;
  }
  for (x = start; x <= end; x++) {
    int xx = x;
    vector<int> z;
    while (xx > 0) {
      z.emplace_back(xx % 10);
      xx /= 10;
    }
    reverse(z.begin(), z.end());
    if (z.size() != n) {
      continue;
    }
    bool valid = true;
    for (i = 0; i < n; i++) {
      if (used[i] >= 0 && (used[i] != z[n - 1 - i])) valid = false;
    }
    if (valid) {
      cout << x << endl;
      return;
    }
  }
  cout << "-1" << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    run();
  }
}
