#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7, INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    v[i] = make_pair(s, c);
  }
  sort(v.begin(), v.end());
  vector<int> ans(n, -1);
  if (n != 1 && v[0].first == 1 && v[0].second == 0) {
    cout << "-1" << endl;
    system("pause");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if ((ans[v[i].first - 1] != -1 && ans[v[i].first - 1] != v[i].second)) {
      if (n == 1 && v[i].first == 1 && v[i].second == 0) continue;
      cout << "-1" << endl;
      system("pause");
      return 0;
    }
    ans[v[i].first - 1] = v[i].second;
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  if (ans[0] == 0 && n != 1) {
    ans[0] = 1;
  }
  for (int i = 0; i < (n); i++) {
    cout << ans[i];
  }
  cout << endl;
  system("pause");
}
