#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int solve(int n) {
  if (n == 0) {
    return 1;
  }
  int num = 0;
  while (n) {
    n /= 10;
    num++;
  }
  return num;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int s, c;
  int mi = 1e9;
  string ans = "";
  for (int i = 0; i < n; i++) {
    ans += "#";
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    mi = min(mi, s - 1);
    if (ans[s - 1] != '#' && c != (ans[s - 1] - '0')) {
      cout << -1 << endl;
      return 0;
    }
    if ((s == 1 && c == 0) && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    ans[s - 1] = ('0' + c);
  }
  if (ans[0] == '#') {
    ans[0] = '1';
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == '#') {
      ans[i] = '0';
    }
  }
  cout << ans << endl;
  return 0;
}
