#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);
long long int lcm(long long int x, long long int y);
long long int bur(long long int N, long long int X);
std::vector<long long int> enum_div(long long int n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;
long long int co[300][300] = {};
vector<bool> is_prime(1000000);
vector<long long int> P;
void Eratosthenes(const long long int N) {
  for (long long int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (long long int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (long long int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
}
class UnionFind {
 public:
  vector<int> Parent;
  UnionFind(int N) { Parent = vector<int>(N, -1); }
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  int size(int A) { return -Parent[root(A)]; }
  int connect(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) {
      return false;
    }
    if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};
int main(void) {
  long long int N = 0;
  long long int A = 0;
  long long int B = 0;
  long long int C = 0;
  long long int D = 0;
  long long int K = 0;
  long long int M = 0;
  long long int L = 1;
  long long int Q = 1000000007;
  string S, T, U[52];
  char fi[50], fv[50];
  char board[4][4];
  long long int count = 0;
  double count2 = 0;
  float n = 0;
  long long int min = 300000000;
  long long int max = 1, max2 = 0, max3 = 0, max4 = 0;
  float dist1 = 0;
  float dist2;
  float dist3 = 1;
  long long int dist4 = 0;
  float now = 0;
  int tmax = 10000;
  int tmax2 = 0;
  bool start = false;
  long long int left = 0, right = 0;
  cin >> N >> M;
  vector<pair<long long int, long long int>> gue(M);
  vector<long long int> gnum(N);
  for (long long int i = (0); i < (M); ++i) {
    cin >> gue[i].first >> gue[i].second;
    gue[i].first--;
  }
  for (long long int i = (0); i < (N); ++i) gnum[i] = 10;
  for (long long int i = (0); i < (M); ++i) {
    if (gnum[gue[i].first] != 10 && gnum[gue[i].first] != gue[i].second) {
      cout << -1 << endl;
      return 0;
    } else {
      gnum[gue[i].first] = gue[i].second;
    }
  }
  if (N == 1 && gnum[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (gnum[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long int i = (0); i < (N); ++i) {
    if (gnum[i] == 10) {
      gnum[i] = 0;
    }
  }
  for (long long int i = (0); i < (N); ++i) {
    cout << gnum[i];
  }
  cout << endl;
  return 0;
}
std::vector<long long int> enum_div(long long int n) {
  vector<long long int> res;
  for (long long int i = 1; i * i <= n; ++i) {
    if (n % i != 0) continue;
    res.push_back(i);
    if (n / i == i) continue;
    res.push_back(n / i);
  }
  return res;
}
long long int bur(long long int N, long long int X) {
  long long int pan = 1;
  long long int pat = 1;
  long long int burg = 0;
  if (X > burg) {
    if (N == 0) return pat;
    burg += pan;
    burg += bur(N - 1, X);
    burg += pat;
    burg += bur(N - 1, X);
    burg += pan;
  }
  return burg;
}
long long int gcd(long long int a, long long int b) {
  if (a < b) {
    long long int tmp = a;
    a = b;
    b = tmp;
  }
  long long int x = b;
  long long int y = a;
  long long int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return y / b * x;
}
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
long long int lcm(long long int x, long long int y) {
  if (x == 0 || y == 0) {
    return 0;
  }
  return (x * y / gcd(x, y));
}
long long comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,
                                        std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}
