#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;
  int yobo[3];
  for (i = 0; i < n; i++) {
    yobo[i] = -1;
  }
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (yobo[a] != -1 && yobo[a] != b) {
      cout << -1;
      return 0;
    }
    yobo[a] = b;
  }
  if (n != 1 && yobo[0] == 0) {
    cout << -1;
    return 0;
  }
  for (i = 0; i < n; i++) {
    int ans = (yobo[i] == -1) ? 0 : yobo[i];
    cout << ans;
  }
  return 0;
}
