#include <bits/stdc++.h>
using namespace std;
long long ans, mx, sum, mn = 1e8, cnt;
long long a[3], zero = 1e18, one = 1e18, two = 1e18;
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long c, b;
    cin >> c >> b;
    c--;
    if (c == 0 && n == 1 && b == 0)
      zero = min(zero, b);
    else if (c == 0 && n > 1 && b != 0)
      zero = min(zero, b);
    else if (c == 1)
      one = min(one, b);
    else if (c == 2)
      two = min(two, b);
  }
  a[0] = zero;
  a[1] = one;
  a[2] = two;
  if (n == 1) {
    if (a[0] == 1e18)
      cout << -1;
    else
      cout << a[0];
  } else if (a[0] == 1e18)
    cout << -1;
  else {
    for (long long i = 0; i < n; i++) {
      if (a[i] == 1e18)
        cout << 0;
      else
        cout << a[i];
    }
  }
}
