#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = (int)2e5 + 5;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n];
  memset(a, 10, n);
  bool ok = 0, okk = 0;
  while (m--) {
    int s, x;
    cin >> s >> x;
    --s;
    a[s] = min(a[s], x);
    if (s == 0) ok = 1;
    if (s == 1) okk = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (i == 0 && a[i] == 10)
      a[0] = 1;
    else if (a[i] == 10)
      a[i] = 0;
  }
  if (ok && okk)
    for (int i = 0; i < n; ++i) cout << a[i];
  else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
