#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1000000000;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  bool res = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] != -1 && a[s] != c) {
      res = false;
      break;
    }
    a[s] = c;
  }
  int cur = true;
  for (int i = 0; i < n; i++) {
    if (cur && a[i] == 0) res = false;
    if (a[i] != 0) cur = false;
  }
  if (a[0] == -1) a[0] = 1;
  if (res) {
    for (int i = 0; i < n; i++) cout << (a[i] == -1 ? 0 : a[i]);
  } else {
    cout << -1;
  }
  cout << endl;
}
