#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 7;
const int mod = 1e9 + 7;
int a[3], b[5];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x - 1] != 0) {
      a[x - 1] = min(a[x - 1], y);
    } else if (a[x - 1] == 0) {
      a[x - 1] = y;
    }
  }
  if (a[0] == 0)
    cout << -1;
  else {
    for (int i = 0; i < n; i++) cout << a[i];
  }
}
