#include <bits/stdc++.h>
using namespace std;
class ParseError {};
template <typename T>
class Zip {
  vector<T> d;
  bool flag;
  void init() {
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    flag = false;
  }

 public:
  Zip() { flag = false; }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  long long getNum(T x) {
    if (flag) init();
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  long long size() {
    if (flag) init();
    return (long long)d.size();
  }
};
long long N, M, K, a, b, c, d, e, H, W, L, T;
long long x, y;
long long A[2000004] = {};
long long B[2000004] = {};
long long C[2000004] = {};
long long D[1000006] = {};
long long E[1000006] = {};
bool f;
string S[200000];
string SS;
set<long long> sll;
pair<long long, long long> bufpl;
vector<long long> vl[100005];
vector<long long> llv[30005];
vector<long long> vll;
vector<long long> v;
vector<pair<long long, long long> > vpl;
vector<string> vs;
set<long long> llset;
multiset<long long> llmset;
queue<long long> ql;
multiset<pair<long long, long long> > plmset;
typedef struct ST {
  long long first;
  long long second;
  long long cost;
  bool operator<(const ST& another) const { return first < another.first; };
  bool operator>(const ST& another) const { return first > another.first; };
} ST;
priority_queue<ST, vector<ST>, greater<ST> > qst;
multiset<ST> stmset;
ST bufst;
ST stt[100000];
long long modinv(long long aa, long long mm) {
  long long bb = mm, uu = 1, vv = 0;
  while (bb) {
    long long tt = aa / bb;
    aa -= tt * bb;
    swap(aa, bb);
    uu -= tt * vv;
    swap(uu, vv);
  }
  uu %= mm;
  if (uu < 0) uu += mm;
  return uu;
}
long long zettai(long long aa) {
  if (aa < 0) {
    aa *= -1;
  }
  return aa;
}
float zettai(float aa) {
  if (aa < 0) {
    aa *= -1;
  }
  return aa;
}
class UnionFind {
 public:
  vector<long long> pairent;
  vector<long long> depth;
  vector<long long> size;
  UnionFind(long long Amount)
      : pairent(Amount, 1), depth(Amount, 1), size(Amount, 1) {
    for (long long i = 0; i < Amount; i++) {
      pairent[i] = i;
    }
  }
  long long FindPairent(long long x) {
    if (pairent[x] == x)
      return x;
    else
      return pairent[x] = FindPairent(pairent[x]);
  }
  long long Merge(long long x, long long y) {
    x = FindPairent(x);
    y = FindPairent(y);
    if (x != y) {
      if (depth[x] > depth[y]) {
        pairent[y] = pairent[x];
        return size[x] += size[y];
      } else {
        pairent[x] = pairent[y];
        if (depth[x] == depth[y]) {
          depth[y]++;
        }
        return size[y] += size[x];
      }
    } else {
      return -1;
    }
  }
  bool IsSame(long long x, long long y) {
    if (FindPairent(x) == FindPairent(y))
      return true;
    else
      return false;
  }
  long long GetSize(long long x) {
    x = FindPairent(x);
    return size[x];
  }
};
class Nibutan {
 public:
  long long hidari = 0;
  long long migi = 0;
  long long abc;
  vector<long long> contents;
  bool Jouken(int ser) {
    if (contents[ser] > abc) {
      return true;
    } else {
      return false;
    }
  }
  void Settings(int amount, long long terget) {
    migi = amount - 1;
    abc = terget;
  }
  long long tansaku() {
    hidari = -1;
    migi = contents.size();
    long long jud;
    while (hidari != migi - 1) {
      jud = hidari + migi;
      jud /= 2;
      if (Jouken(jud)) {
        migi = jud;
      } else {
        hidari = jud;
      }
    }
    return hidari;
  }
};
long long RepeatSquaring(long long N, long long P, long long M) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    long long t = RepeatSquaring(N, P / 2, M) % M;
    return t * t % M;
  }
  return N * RepeatSquaring(N, P - 1, M) % M;
}
long long GCD(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return GCD(b, a % b);
}
long long Min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long Max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long Sum(long long a, long long b) { return a + b; }
template <typename T>
class SegmentTree {
  long long n;
  vector<T> node;
  function<T(T, T)> fun, fun2;
  bool customChange;
  T outValue, initValue;

 public:
  void init(long long num, function<T(T, T)> resultFunction, T init, T out,
            function<T(T, T)> changeFunction = NULL) {
    fun = resultFunction;
    fun2 = changeFunction;
    customChange = changeFunction != NULL;
    n = 1;
    while (n < num) n *= 2;
    node.resize(2 * n - 1);
    fill(node.begin(), node.end(), init);
    outValue = out;
    initValue = init;
  }
  void valueChange(long long num, T value) {
    num += n - 1;
    if (customChange)
      node[num] = fun2(value, node[num]);
    else
      node[num] = value;
    while (num > 0)
      num = (num - 1) / 2,
      node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
  }
  T rangeQuery(long long a, long long b, long long l = 0, long long r = -1,
               long long k = 0) {
    if (r == -1) r = n;
    if (a <= l && r <= b) return node[k];
    if (b <= l || r <= a) return outValue;
    long long mid = (l + r) / 2;
    return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
               rangeQuery(a, b, mid, r, 2 * k + 2));
  }
};
bool gone[200002] = {};
void DFS(long long num, long long count) {
  count++;
  gone[num] = true;
  for (long long i = 0; i < vl[num].size(); i++) {
    if (gone[vl[num][i]] == false) {
      gone[vl[num][i]] = true;
      DFS(vl[num][i], count);
    }
  }
  D[num] = count;
}
void DFS2(long long num, long long count) {
  count++;
  gone[num] = true;
  for (long long i = 0; i < vl[num].size(); i++) {
    if (gone[vl[num][i]] == false) {
      gone[vl[num][i]] = true;
      DFS2(vl[num][i], count);
    }
  }
  E[num] = count;
}
long long conb(long long n, long long k, long long mod) {
  long long a = C[n];
  a *= D[k];
  a %= mod;
  a *= D[n - k];
  a %= 1000000007;
  return a;
}
int main() {
  cin >> N >> M;
  for (long long i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i] = N - A[i];
  }
  a = 1;
  for (long long i = 1; i < N; i++) {
    a *= 10;
  }
  for (long long i = a; i < a * 10; i++) {
    b = i;
    c = 0;
    while (b > 0) {
      C[c] = b % 10;
      c++;
      b /= 10;
    }
    f = true;
    for (long long j = 0; j < M; j++) {
      if (C[A[j]] != B[j]) f = false;
    }
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
