#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
int main() {
  int dig[4];
  for (int i = 0; i < (4); i++) dig[i] = -1;
  int N, M;
  cin >> N >> M;
  bool f = true;
  for (int i = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    if (dig[s] == -1)
      dig[s] = c;
    else if (dig[s] != c)
      f = false;
    else
      dig[s] = c;
  }
  if (dig[1] == 0) f = false;
  if (f) {
    for (int i = 0; i < (M); i++) {
      if (dig[i + 1] > 0)
        cout << dig[i];
      else
        cout << 0;
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
