#include <bits/stdc++.h>
using namespace std;
void run_case() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, -1);
  int mx = 0;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    mx = max(s, mx);
    if (a[s] == -1 || a[s] == c)
      a[s] = c;
    else {
      cout << -1;
      return;
    }
  }
  if (mx != n || a[1] == -1)
    cout << -1;
  else {
    for (int i = 1; i <= n; ++i) cout << (a[i] == -1 ? 0 : a[i]);
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cout.flags(ios::fixed);
  cout.precision(9);
  run_case();
  cout.flush();
  return 0;
}
