#include <bits/stdc++.h>
using namespace std;
int a[5];
int s[10], c[10];
vector<pair<int, int> > v;
int main() {
  int n, m;
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    v.push_back(make_pair(s[i], c[i]));
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  if (v.size() > n) {
    cout << "-1";
  } else {
    int ans[5];
    for (int i = 1; i <= n; i++) ans[i] = -1;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].first == v[i - 1].first) {
        cout << "-1";
        return 0;
      }
      ans[v[i].first] = v[i].second;
    }
    if (ans[1] == 0)
      cout << "-1";
    else if (ans[1] == -1) {
      cout << "1";
      for (int i = 2; i <= n; i++) cout << (ans[i] == -1 ? 0 : ans[i]);
    } else {
      for (int i = 1; i <= n; i++) cout << (ans[i] == -1 ? 0 : ans[i]);
    }
  }
  return 0;
}
