#include <bits/stdc++.h>
using namespace std;
int on_bit(int N, int pos) { return N = N | (1 << pos); }
int off_bit(int N, int pos) { return N = N & ~(1 << pos); }
bool check_bit(long long int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1)
      cout << "0\n";
    else {
      cout << "1";
      for (int i = 1; i < n; i++) cout << "0";
      cout << "\n";
    }
    return 0;
  }
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  bool flg = 0;
  for (int i = 0; i < m - 1; i++) {
    if (v[i].first == v[i + 1].first and v[i].second != v[i].second) {
      flg = 1;
      break;
    }
  }
  if (flg)
    cout << "-1\n";
  else {
    vector<int> ar(10, 0);
    for (int i = 0; i < m; i++) {
      ar[v[i].first] = v[i].second;
    }
    if (n > 1 && ar[1] == 0)
      cout << "-1\n";
    else {
      for (int i = 1; i <= n; i++) cout << ar[i];
      cout << "\n";
    }
  }
  return 0;
}
