#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool st[N];
int solved() {
  int n, m;
  cin >> n >> m;
  pair<int, int> p[N];
  int flag = 0;
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
    if (p[i].second == 0 && p[i].first != 1) flag = 1;
  }
  sort(p, p + m);
  if (n > 1 && p[0].first == 1 && p[0].second == 0) return -1;
  vector<pair<int, int> > t;
  vector<vector<int> > a(N);
  for (int i = 0; i < m; i++) {
    st[p[i].first] = true;
    if (a[p[i].first].size() < 1) {
      a[p[i].first].push_back(p[i].second);
      t.push_back(p[i]);
    } else {
      if (a[p[i].first][0] != p[i].second) return -1;
    }
  }
  if (p[0].first == 1 && p[0].second == 0 && t.size() > 1) return -1;
  long long ans = 0;
  int ff = 0;
  for (int i = 1; i <= p[m - 1].first; i++) {
    if (a[i].size() != 0) {
      cout << a[i][0];
      ff = 1;
    } else if (flag == 1 && i == 1) {
      cout << 1;
    } else if (ff == 1) {
      cout << 0;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = solved();
  if (t == -1) cout << -1;
  return 0;
}
