#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
using Vecint = vector<lint>;
lint pow10(lint k) {
  lint ret = 1;
  for (lint(i) = 0; (i) < (lint)(k); (i)++) {
    ret *= 10;
  }
  return ret;
}
void Main() {
  lint N, M, ans = 0;
  vector<pair<lint, lint>> pairs(M);
  cin >> N >> M;
  for (lint(i) = 0; (i) < (lint)(M); (i)++) {
    lint x, y;
    cin >> x >> y;
    if ((3 - x) > N) {
      cout << "-1" << '\n';
      return;
    }
    pairs.push_back(pair<lint, lint>(x, y));
  }
  for (lint(i) = 0; (i) < (lint)(M); (i)++) {
    for (lint(j) = (1); (j) < (M + 1); ++(j)) {
      if (pairs[i].first == pairs[j].first && pairs[i] != pairs[j]) {
        cout << "-1" << '\n';
        return;
      }
    }
  }
  for (lint(i) = 0; (i) < (lint)(M); (i)++) {
    if (ans / pow10((3 - pairs[i].first)) != pairs[i].second) {
      ans += pow10((3 - pairs[i].first)) * pairs[i].second;
    }
  }
  cout << ans << '\n';
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Main();
  return 0;
}
