#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> ans(n);
  vector<int> count(n);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    int x = s[i] - 1;
    int y = c[i];
    if (x == 0 && y == 0) {
      cout << -1 << endl;
      return 0;
    } else if (count[x] > 0 && ans[x] != y) {
      cout << -1 << endl;
      return 0;
    } else {
      ans[x] = y;
      count[x] += 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == 0 && ans[i] == 0) {
      cout << 1;
    } else if (ans[i] == 0) {
      cout << 0;
    } else {
      cout << ans[i];
    }
  }
}
