#include <bits/stdc++.h>
using namespace std;
using LL = long long;
bool flag = false;
signed main() {
  string ans = "";
  LL n, m;
  cin >> n >> m;
  vector<pair<int, bool>> a(n + 1);
  for (LL i = 0; i < (int)(n + 1); i++) a[i] = make_pair(10000, false);
  for (LL i = 0; i < (int)(m); i++) {
    int t, s;
    cin >> t >> s;
    if (a[t].second == false || a[t].first == s) {
      a[t].first = s;
      a[t].second = true;
    } else {
      cout << -1;
      return 0;
    }
  }
  if (a[1].first == 0 && n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i].first != 0) flag = true;
    if (flag) {
      if (a[i].first == 10000) a[i].first = 0;
      ans += to_string(a[i].first);
    }
  }
  if (ans[0] == 0) ans[0] = '1';
  cout << ans;
}
