#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int digits[5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  memset(digits, -1, sizeof(digits));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1;
      return 0;
    }
    if (digits[s] != -1 && digits[s] != c) {
      cout << -1;
      return 0;
    }
    digits[s] = c;
  }
  for (int i = 1; i <= n; i++) {
    if (digits[i] == -1) {
      if (i == 1)
        cout << 1;
      else
        cout << 0;
    } else
      cout << digits[i];
  }
  return 0;
}
