#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int TN = 1;
void solve() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<pair<int, int>> conds;
  vector<int> a(n, 0);
  for (int i = 0; i < m; ++i) {
    int s;
    int c;
    cin >> s >> c;
    --s;
    conds.push_back({s, c});
    a[s] = c;
  }
  for (int i = 0; i < m; ++i) {
    if (a[conds[i].first] != conds[i].second) {
      cout << -1;
      return;
    }
  }
  if (n > 1 && a[0] == 0) {
    cout << -1;
    return;
  }
  for (int i : a) {
    cout << i;
  }
}
int main() {
  auto start = chrono::steady_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  while (TN--) {
    solve();
  }
  auto finish = chrono::steady_clock::now();
  auto elapsed_ms = chrono::duration_cast<chrono::milliseconds>(finish - start);
  cerr << endl << "Time: " << elapsed_ms.count() << " ms\n";
  return 0;
}
