#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int maxn = 2000100;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  string s = string(n, '#');
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (s[a] != '#' && (s[a] - '0') != b) {
      ok = false;
    } else {
      s[a] = b + '0';
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '#') s[i] = '0';
  }
  if (!ok || (n > 1 && s[0] == '0')) {
    cout << -1 << "\n";
  } else
    cout << s << "\n";
  return 0;
}
