#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
const int ARRAY = 100005;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int MOD = 1e9 + 7;
ll N = 0;
ll M = 0;
ll C[3];
ll t;
ll ret = 0;
string s;
bool ok = true;
void input() {
  cin >> N;
  cin >> M;
  for (int i = 0; i < (3); i++) {
    C[i] = -1;
  }
  for (int i = 0; i < (M); i++) {
    ll s, c;
    cin >> s;
    cin >> c;
    if (C[s - 1] == -1) {
      C[s - 1] = c;
    } else {
      if (C[s - 1] != c) {
        ok = false;
      }
    }
  }
}
void solve() {
  if (C[0] == 0) ok = false;
  if (!ok) {
    cout << (-1) << endl;
    return;
  }
  if (M == 0) {
    cout << (0) << endl;
    return;
  }
  for (int i = 0; i < (N); i++) {
    if (i == 0) {
      if (C[i] == -1) {
        cout << 1;
      } else {
        cout << C[i];
      }
    } else {
      if (C[i] == -1) {
        cout << 0;
      } else {
        cout << C[i];
      }
    }
  }
  cout << endl;
}
int main(void) {
  input();
  solve();
}
