#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline bool inside(int y, int x, int H, int W) {
  return (y >= 0 && x >= 0 && y < H && x < W);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vi s(m), c(m);
  for (int i = (int)(0); i < (int)(m); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  string S = "";
  for (int i = (int)(0); i < (int)(n); ++i) {
    S += "0";
  }
  vi a(n, -1);
  for (int i = (int)(0); i < (int)(m); ++i) {
    if (a[s[i]] != -1 && a[s[i]] != c[i] || s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    a[s[i]] = c[i];
    S[s[i]] = ('0' + c[i]);
  }
  if (n != 1 && S[0] == '0') S[0] = '1';
  cout << S << endl;
}
