#include <bits/stdc++.h>
using namespace std;
long long dig[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(0);
  long long a, b, pos, num;
  bool bruh = false;
  cin >> a >> b;
  for (int i = 0; i < b; i++) {
    cin >> pos >> num;
    if (dig[pos - 1] == 0 || dig[pos - 1] == num) {
      dig[pos - 1] = num;
    } else {
      bruh = true;
    }
  }
  if (bruh == true) {
    cout << "-1";
    return 0;
  }
  if (a == 1) {
    cout << dig[0];
  } else {
    if (dig[0] == 0) {
      cout << "-1";
    } else {
      for (int i = 0; i < a; i++) cout << dig[i];
    }
  }
  return 0;
}
