#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vect;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (u == 1) {
      if (v != 0) vect.push_back(make_pair(u, v));
    } else
      vect.push_back(make_pair(u, v));
  }
  sort(vect.begin(), vect.end());
  int num = 0;
  int count = 0;
  for (int i = 1; i <= n; i++) {
    int g = 0, x;
    for (int j = 0; j < vect.size(); j++) {
      if (i == vect[j].first) {
        if (g == 0) {
          g = 1;
          x = vect[j].second;
        }
      }
    }
    if (i == 1) {
      if (g == 0) {
        count = 1;
        break;
      } else
        num = x;
    } else {
      if (g == 0)
        num = num * 10;
      else
        num = num * 10 + x;
    }
  }
  if (count == 1)
    cout << "-1";
  else {
    int r = num;
    int digit = 0;
    while (r > 0) {
      r = r / 10;
      digit++;
    }
    if (digit == n)
      cout << num;
    else
      cout << "-1";
  }
}
