#include <bits/stdc++.h>
using namespace std;
long long llRead() {
  long long a;
  cin >> a;
  return a;
};
string stringRead() {
  string a;
  cin >> a;
  return a;
};
vector<long long> vlRead(long long a) {
  vector<long long> rv;
  for (long long i = (0); i < (a); i++) {
    long long input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<string> vsRead(long long a) {
  vector<string> rv;
  for (long long i = (0); i < (a); i++) {
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<pair<long long, long long>> vpRead(long long n) {
  vector<pair<long long, long long>> rv;
  for (long long i = (0); i < (n); i++) {
    auto a = llRead();
    auto b = llRead();
    rv.push_back(make_pair(a, b));
  }
  return rv;
}
vector<vector<long long>> vvlRead(long long a, long long b) {
  vector<vector<long long>> rv;
  for (long long i = (0); i < (a); i++) {
    rv.push_back(vector<long long>());
    for (long long j = (0); j < (b); j++) {
      long long input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}
vector<vector<char>> vvcRead(long long a, long long b) {
  vector<vector<char>> rv;
  for (long long i = (0); i < (a); i++) {
    rv.push_back(vector<char>());
    for (long long j = (0); j < (b); j++) {
      char input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}
long long factm(long long n) {
  ;
  long long ret = 1;
  for (long long i = (2); i < (n + 1); i++) {
    ret *= i;
    ret = ret % (1000000007);
  };
  return ret;
}
long long inv(long long a) {
  long long b = (1000000007), u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= (1000000007);
  if (u < 0) u += (1000000007);
  return u;
}
int main(int argc, const char* argv[]) {
  cout.precision(16);
  auto N = llRead();
  auto M = llRead();
  auto SCs = vvlRead(M, 2);
  ;
  vector<long long> ds(N);
  for (long long i = (0); i < (N); i++) {
    ds.at(i) = -1;
  };
  for (auto i : SCs) {
    auto s = i.at(0) - 1;
    auto c = i.at(1);
    if (ds.at(s) == -1) {
      ds.at(s) = c;
    } else if (ds.at(s) == c) {
    } else {
      cout << -1 << endl;
      return 0;
    }
  };
  if (ds.at(0) == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (ds.at(0) == -1) {
    ds.at(0) = 1;
  };
  for (auto i : ds) {
    ;
    cout << ((i == -1) ? 0 : i);
  }
  cout << endl;
  return 0;
}
