#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), cnt(n);
  int s, c;
  bool flag = true;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (cnt[s - 1] != 0 && c != a[s - 1]) flag = false;
    a[s - 1] = c;
    cnt[s - 1]++;
  }
  if (cnt[0] != 0 && a[0] == 0) flag = false;
  if (flag) {
    if (a[0] == 0) a[0] = 1;
    for (int i = 0; i < (n); ++i) cout << a[i];
  } else
    cout << -1;
}
