#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  bool ok = true;
  for (int i = 0; i < (int)m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    if (ans[a] != -1 && ans[a] != b) ok = false;
    ans[a] = b;
  }
  if (ans[0] == 0) ok = false;
  if (!ok)
    cout << -1;
  else
    for (int i = 0; i < (int)n; ++i) cout << (ans[i] >= 0 ? ans[i] : 0);
  cout << endl;
  return 0;
}
