#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  bool ans = true;
  vector<int> v(n);
  vector<bool> b(n);
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (!b[x - 1] || v[x - 1] == y)
      v[x - 1] = y;
    else
      ans = false;
  }
  if (v[0] == 0) ans = false;
  if (ans)
    for (auto i : v) cout << i;
  else
    cout << -1;
  return 0;
}
