#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n = m) {
    int a[n];
    for (int i = 0; i < n; i++) a[i] = 11;
    bool flag = false;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      a[x] = min(a[x], y);
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 11) a[i] = 0;
    }
    int no = 0;
    for (int i = 0; i < n; i++) no += a[i] * (pow(10, n - 1 - i));
    cout << no;
  } else
    cout << -1;
}
