#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vec num(n + 1, 0);
  vec ans(n + 1, 0);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if ((s == 1 && c == 0) || (c != ans[s] && ans[s] != 0)) {
      cout << "-1" << endl;
      return 0;
    } else {
      ans[s] = c;
    }
  }
  int num2 = 0;
  for (int i = 1; i <= (int)(n); i++) {
    if (ans[i] == 0 || num2 == 0) num2 = 1;
    if (num2 == 1) cout << ans[i];
  }
  return 0;
}
