#include <bits/stdc++.h>
using namespace std;
long long mem[100010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  bool no = false;
  int s[10], c[10];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) no = true;
  }
  if (no && n != 1) {
    cout << "-1\n";
    return (0);
  }
  int ans[10] = {};
  bool ka[10] = {};
  bool a = false;
  for (int i = 0; i < m; i++) {
    if (ka[s[i]]) {
      if (ans[s[i]] != c[i]) a = true;
    }
    ans[s[i]] = c[i];
    ka[s[i]] = true;
  }
  if (a)
    cout << "-1";
  else
    for (int i = 1; i <= n; i++) cout << ans[i];
  cout << '\n';
  return (0);
}
