#include <bits/stdc++.h>
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < (n); i++) {
    a[i] = 0;
  }
  int flag = 1;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != 0) {
      if (a[s - 1] != c) {
        cout << "-1";
        flag = 0;
        break;
      } else {
      }
    } else {
      a[s - 1] = c;
    }
  }
  if (a[0] == 0 && flag == 1) {
    if (n != 1) {
      cout << "-1";
      flag = 0;
    }
  }
  if (flag == 1) {
    for (int i = 0; i < (n); i++) {
      cout << a[i];
    }
  }
  return 0;
}
