#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int i;
  string ans = "";
  for (i = 0; i < n; i++) {
    ans += "0";
  }
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (n != 1 && a == 0 && b == 0) {
      cout << -1;
      return 0;
    } else if (ans[a] != '0' && ans[a] != b + '0') {
      cout << -1;
      return 0;
    } else {
      char tmp = b + '0';
      ans[a] = tmp;
    }
  }
  if (ans[0] == '0' && n != 1) {
    cout << -1;
    return 0;
  } else {
    cout << ans;
  }
  return 0;
}
