#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, x, y;
  cin >> n >> m;
  int ans[n + 5];
  set<int> pos;
  set<int>::iterator it, it1;
  vector<pair<int, int>> vec;
  memset(ans, -1, sizeof(ans));
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    vec.push_back(make_pair(x, y));
    pos.insert(x);
  }
  for (it = pos.begin(); it != pos.end(); it++) {
    int mini;
    for (i = 0; i < m; i++) {
      if (vec[i].first == *it) {
        mini = vec[i].second;
        break;
      }
    }
    for (i = 0; i < m; i++) {
      if (vec[i].first == *it && vec[i].second < mini) mini = vec[i].second;
    }
    ans[*it] = mini;
  }
  it = pos.begin();
  if (*it != 1) {
    cout << -1 << endl;
    return 0;
  }
  int flag = 0;
  it = pos.end();
  for (i = 1; i <= *it; i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (ans[i] == -1) {
      flag = 1;
      break;
    }
    if (ans[i] == 0) cnt++;
  }
  if (flag || cnt == n)
    cout << -1 << endl;
  else {
    for (i = 1; i <= n; i++) cout << ans[i];
    puts("");
  }
  return 0;
}
