#include <bits/stdc++.h>
using namespace std;
const long long INFLL = 1e18;
const int MAXN = 1e6 + 100;
const long long INF = 1e9;
const long long mod1 = 1e9 + 7;
const long long mod2 = 2e9 + 11;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  vector<int> ans(n, -1);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    s[i]--;
    if (ans[s[i]] == -1 || ans[s[i]] == c[i])
      ans[s[i]] = c[i];
    else
      ok = false;
  }
  if (ans[0] == 0 && n != 1) ok = false;
  if (ok) {
    for (int i = 0; i < (n); i++) cout << max(ans[i], 1);
  } else
    cout << -1;
}
