#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, i, m, num[6], s, c;
  cin >> n >> m;
  memset(num, -1, sizeof(num));
  for (i = 1; i <= m; ++i) {
    cin >> s >> c;
    if (num[s] == -1) {
      num[s] = c;
      continue;
    } else {
      if (num[s] != c) {
        cout << -1 << endl;
        return;
      }
    }
  }
  if (num[1] == 0 && n != 1) {
    cout << -1 << endl;
    return;
  }
  if (num[1] == -1) {
    if (n != 1)
      num[1] = 1;
    else {
      num[1] = 0;
    }
  }
  for (i = 1; i <= m; ++i) {
    if (num[i] == -1) num[i] = 0;
    cout << num[i];
  }
  cout << endl;
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
