#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void iostream_init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(12);
}
int main() {
  ::iostream_init();
  int N;
  int M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (long long i = long long(0); i < long long(M); ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  sort((sc).begin(), (sc).end());
  sc.erase(unique((sc).begin(), (sc).end()), sc.end());
  ;
  vector<int> sz(M);
  for (long long i = long long(0); i < long long(((int)(sc).size())); ++i) {
    sz[i] = sc[i].first;
  }
  int old_size = ((int)(sz).size());
  sort((sz).begin(), (sz).end());
  sz.erase(unique((sz).begin(), (sz).end()), sz.end());
  ;
  int new_size = ((int)(sz).size());
  if (old_size == new_size) {
    sort((sc).rbegin(), (sc).rend());
    vector<int> tmp(N, 0);
    for (long long i = long long(0); i < long long(((int)(sc).size())); ++i) {
      tmp[sc[i].first - 1] = sc[i].second;
    }
    string ans = "";
    for (long long i = long long(0); i < long long(N); ++i) {
      ans += to_string(tmp[i]);
    }
    int ret = stoi(ans);
    if (ret != 0 && ans == to_string(ret)) {
      cout << (ret) << "\n";
    } else {
      cout << ("-1") << "\n";
    }
  } else {
    cout << ("-1") << "\n";
  }
  return 0;
}
