#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mo = 1e9 + 7;
constexpr int inf = 1 << 30;
constexpr ll infl = 1ll << 60;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s(n, '-');
  bool ok = true;
  for (int i = 0; i < m; ++i) {
    int si, c;
    cin >> si >> c;
    si--;
    if (s[si] == '-')
      s[si] = (char)(c + '0');
    else if (s[si] != '-' and (s[si] - '0') != c) {
      ok = false;
      break;
    }
  }
  if (s[0] == '-' or s[0] == '0')
    ok = false;
  else {
    for (int i = 1; i < n; ++i) {
      if (s[i] == '-') s[i] = '0';
    }
  }
  if (ok)
    cout << s << endl;
  else
    cout << -1 << endl;
  return 0;
}
