#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a;
vector<int> track;
map<int, int> s;
void solve() {
  for (auto x : s) {
    a[x.first - 1] = x.second;
  }
  if (a[0] == 0 && n >= 2) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    a.push_back(0);
    track.push_back(0);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (track[x - 1] == 0 || s[x] == y) {
      track[x - 1]++;
      s[x] = y;
    } else {
      cout << -1;
      return 0;
    }
  }
  solve();
  return 0;
}
