#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (int i = 0; i < m; i++) cin >> sc[i].first >> sc[i].second;
  sort(sc.begin(), sc.end());
  vector<int> ans(n, -1);
  bool is_exist = true;
  for (int i = 0; i < m; i++) {
    int digit = sc[i].first - 1;
    int num = sc[i].second;
    if (ans[digit] == -1) {
      ans[digit] = num;
    } else if (ans[digit] != num) {
      is_exist = false;
      break;
    }
  }
  if (!is_exist) {
    cout << -1 << endl;
  } else {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1) ans[i] = 0;
      sum += ans[i];
    }
    if (n != 1 && sum == 0) {
      cout << -1 << endl;
    } else {
      for (auto c : ans) {
        cout << c;
      }
      cout << endl;
    }
  }
  return 0;
}
