#include <bits/stdc++.h>
using namespace std;
struct Fast {
  Fast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast;
int main() {
  long long n, m, sum = 0, n1 = 0, n2 = 0, n3 = 0;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  map<int, int> cnt;
  for (long long i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
    if (s[i] == 1) {
      n1 = c[i];
    }
    if (s[i] == 2) {
      n2 = c[i];
    }
    if (s[i] == 3) {
      n3 = c[i];
    }
  }
  for (long long i = 0; i < m; i++) {
    if (cnt.count(s[i])) {
      if (cnt[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cnt[s[i]] = c[i];
  }
  if (n == 1) {
    if (s[0] == 1 && c[0] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (cnt.count(1) && cnt[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3) {
    cout << n1 * 100 + n2 * 10 + n3 << endl;
  }
  if (n == 2) {
    cout << n1 * 10 + n2 << endl;
  }
  if (n == 1) {
    cout << n1 << endl;
  }
}
