#include <bits/stdc++.h>
using namespace std;
const long long INF = 1001001001;
const long long LINF = 1001001001001001001;
const long long D4[] = {0, 1, 0, -1, 0};
const long long D8[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = (long long)(0); i <= (long long)((m)-1); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<long long> a(n, -1);
  for (long long i = (long long)(0); i <= (long long)((m)-1); ++i) {
    if (a[s[i]] != -1 && a[s[i]] != c[i]) {
      cout << -1 << endl;
      return;
    }
    a[s[i]] = c[i];
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (a[0] == -1) a[0] = 1;
  for (long long i = (long long)(0); i <= (long long)((n)-1); ++i) {
    cout << (a[i] == -1 ? 0 : a[i]);
  }
  cout << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}
