#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, keta = 0, s, c;
  cin >> n >> m;
  vector<int> d(3, -1);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (d[s - 1] == -1) {
      d[s - 1] = c;
    } else if (d[s - 1] != c) {
      cout << -1;
      return 0;
    }
    keta = max(keta, s);
  }
  int ans = 0;
  for (int i = 0; i < keta; i++) {
    ans *= 10;
    if (d[i] == -1) {
      continue;
    } else {
      ans += d[i];
    }
  }
  cout << ans;
}
