#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n, m, k, i, j;
  string s;
  cin >> n >> m;
  vector<int> arr(3);
  for (i = 0; i < 3; i++) arr[i] = 100;
  set<int> v;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    arr[a - 1] = min(arr[a - 1], b);
    v.insert(a);
  }
  if (find(v.begin(), v.end(), n) != v.end()) {
    for (i = 0; i < n; i++)
      if (arr[i] == 100)
        cout << 0;
      else
        cout << arr[i];
  } else
    cout << "-1" << endl;
}
