#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 1e18;
using P = pair<int, int>;
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s[5] = {}, f, x[10] = {};
  char c[5] = {}, xx[10] = {};
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (n == 2) {
      cout << 10 << endl;
      return 0;
    }
    if (n == 3) {
      cout << 100 << endl;
      return 0;
    }
  }
  string ans = "";
  for (int i = 0; i < n; i++) {
    ans += "0";
  }
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (x[s[i]] && xx[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    x[s[i]] = 1, xx[s[i]] = c[i];
    if (n != 1 && s[i] == 1 && c[i] == '0') {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }
  cout << ans << endl;
}
