#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans[n + 1];
  memset(ans, -1, sizeof ans);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s] != -1 && ans[s] != c) {
      ok = false;
      break;
    }
    ans[s] = c;
  }
  if ((ans[0] == 0 && n != 1) || !ok)
    cout << -1 << '\n';
  else {
    for (int i = 1; i <= n; i++) cout << (ans[i] == -1 ? 0 : ans[i]);
    cout << '\n';
  }
}
