#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<P> v(m);
  for (int i = 0; i < m; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort((v).begin(), (v).end());
  for (int i = 0; i < m - 1; ++i) {
    if (v[i].first == v[i + 1].first) {
      if (v[i].second != v[i + 1].second) {
        cout << -1 << "\n";
        return 0;
      }
    }
  }
  vector<int> ans(n);
  if (v[0].first != 1) {
    ans[0] = 1;
  }
  for (int i = 0; i < m; ++i) {
    ans[v[i].first - 1] = v[i].second;
  }
  for (auto& p : ans) {
    cout << p;
  }
  cout << "\n";
  return 0;
}
