#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class X>
void printArray(X *array, long long);
template <class X>
void printVector(vector<X> &v);
template <class X>
void printDimention(vector<vector<X> > &dv);
template <class X>
void printMap(X);
template <class X>
void printVecPair(vector<X> &v);
void printDV_Pair(vector<vector<pair<long long, long long> > > &v);
void printSet(set<long long> &S);
long long RepeatSquaring(long long a, long long index);
long long GCD(long long, long long);
long long LCM(long long, long long);
long long div_one(long long res, long long div);
const int MOD = 1000000007;
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;
long long n, N, k, K, V, E;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long M;
  cin >> N >> M;
  vector<long long> num(N);
  vector<bool> con(N, false);
  bool no = false;
  for (long long i = (0); i < (M); ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (!c) {
      if (((N == 2 || N == 3) && s == 0)) {
        no = true;
        break;
      }
    }
    if (!con[s]) {
      num[s] = c;
      con[s] = true;
    } else {
      if (num[s] != c) {
        no = true;
        break;
      }
    }
  }
  if (!con[0]) {
    num[0] = 1;
  } else {
    if (num[0] == 0) no = true;
  }
  if (!no) {
    for (long long i = (0); i < (N); ++i) {
      cout << num[i];
    }
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}
template <class X>
void printArray(X array[], long long n) {
  for (long long i = (0); i < (n); ++i) {
    if (i) cout << " ";
    cout << array[i];
  }
  cout << endl;
}
template <class X>
void printVector(vector<X> &v) {
  for (long long i = (0); i < ((int)v.size()); ++i) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
template <class X>
void printDimention(vector<vector<X> > &dv) {
  for (long long i = (0); i < ((long long)dv.size()); ++i) {
    for (long long j = (0); j < ((long long)dv[i].size()); ++j) {
      if (j) cout << " ";
      cout << dv[i][j];
    }
    cout << endl;
  }
  cout << endl;
}
template <class X>
void printMap(X mp) {
  for (auto it : mp) {
    cout << it.first << " " << it.second << endl;
  }
}
template <class X>
void printVecPair(vector<X> &v) {
  for (long long i = (0); i < ((int)v.size()); ++i) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  cout << endl;
}
void printDV_Pair(vector<vector<pair<long long, long long> > > &v) {
  for (long long i = (0); i < ((int)v.size()); ++i) {
    cout << i << endl;
    for (long long j = (0); j < ((int)v[i].size()); ++j) {
      cout << v[i][j].first << " " << v[i][j].second << endl;
    }
    cout << endl;
  }
  cout << endl;
}
void printSet(set<long long> &S) {
  for (set<long long>::iterator it = S.begin(); it != S.end(); it++) {
    if (it != --S.end())
      cout << *it << " ";
    else
      cout << *it << endl;
  }
}
long long RepeatSquaring(long long a, long long index) {
  if (index == 0)
    return 1;
  else if (index % 2 == 0) {
    long long tmp = RepeatSquaring(a, index / 2);
    return tmp * tmp;
  } else {
    return a * RepeatSquaring(a, index - 1);
  }
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long m, long long n) {
  if (m == 0 || n == 0) return 0;
  return ((m / GCD(m, n)) * n);
}
long long div_one(long long res, long long div) {
  return (res + div - 1) / div;
}
