//#define __debug

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Security;

namespace _TestData
{
    public static class TestExtensions
    {
        public static string ToStr<T>(this IEnumerable<T> ms)
        {
            return ms.Aggregate("", (current, s) => current + (s + ","));
        }
        public static string Split(this string str, int index, char spliter=' ')
        {
            return str.Split(spliter)[index];
        }
        public static int ToInt(this string str)
        {
            return Convert.ToInt32(str);
        }
        public static char GetChar(this string str, int index)
        {
            return str[index];
        }

        public static int Sum(this int i)
        {
            int ii = 0;
            for (; i != 0;)
            {
                ii += i % 10;
                i = i / 10;
            }
            return ii;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {

#if __debug
            var n = "9999";
#else
            var n = Console.ReadLine();

#endif

            Console.WriteLine(Get(n.ToInt()));
        }

        static void Add(ref string str , int i)
        {
            str += i;
        }
        static string Get(int n)
        {
            string tmp = string.Empty;
            int i = 1;
            while (tmp.Length < n)
            {
                Add(ref tmp, i++);
            }
            //Console.WriteLine(tmp);
            return tmp[n-1].ToString();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string s = "";
            for(int i = 1; i <= k; i++)
                s += i.ToString();
            Console.WriteLine(s[k-1]);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = Int32.Parse(Console.ReadLine());
            string s = "";
            for (int i = 1; i <= 10000; i++)
                s += i;
            Console.Write(s[x-1]);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

             string s="";
             for(int i=0;i<10000;i++)
             s+=i.ToString();
             int n=int.Parse(Console.ReadLine());
             Console.WriteLine(s[n]);
        }

    }
}

using System;

class _1177B
{
	static void Main()
	{
		long k = long.Parse(Console.ReadLine());

		long start = 0;
		long cnt = 9;
		int digit = 1;
		while (k > start)
		{
			start += cnt * digit++;
			cnt *= 10;
		}
		start -= (cnt / 10) * --digit;
		long posFromStart = k - start;
		long numFromStart = (long)Math.Ceiling((double)posFromStart / digit);
		long cntBefore = (long)Math.Pow(10, digit - 1) - 1;
		long num = numFromStart + cntBefore;
		int posDigit = (int)(posFromStart % digit);
		posDigit = (posDigit == 0 ? digit : posDigit) - 1;
		Console.WriteLine(num.ToString()[posDigit]);
	}
}

using System;
using System.IO;
using System.Text;

namespace Digits_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static char Solve(string[] args)
        {
            int n = Next();

            var b = new StringBuilder();
            int i = 1;
            while (b.Length < n)
            {
                b.Append(i++);
            }
            return b[n-1];
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
class Program
{
    static void Main(){
        var n = int.Parse(Console.ReadLine());
            var str = "";
            for(int i = 1; i<5000; i++)
            {
                str += i.ToString();
            }
            Console.WriteLine(str[n-1]);
    }
}

// Problem: 1177A - Digits Sequence (Easy Edition)
// Author: Gusztav Szmolik

using System;

class DigitsSequenceEasyEdition
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        ushort k;
        if (!UInt16.TryParse (words[0], out k))
            return -1;
        if (k < 1 || k > 10000)
            return -1;
        byte ans = 0;
        if (k < 10)
            ans = (byte)k;
        else if (k < 190)
            {
            ushort i = Convert.ToUInt16 (k-10);
            ushort num = Convert.ToUInt16 (10+i/2);
            ans = (i%2 == 0 ? Convert.ToByte (num/10) : Convert.ToByte (num%10));
            }
        else if (k < 2890)
            {
            ushort i = Convert.ToUInt16 (k-190);
            ushort num = Convert.ToUInt16 (100+i/3);
            byte r = Convert.ToByte (i%3);
            if (r == 0)
                ans = Convert.ToByte (num/100);
            else
                ans = (r == 1 ? Convert.ToByte ((num/10)%10) : Convert.ToByte (num%10));
            }
        else
            {
            ushort i = Convert.ToUInt16 (k-2890);
            ushort num = Convert.ToUInt16 (1000+i/4);
            byte r = Convert.ToByte (i%4);
            switch (r)
                {
                case 0: ans = Convert.ToByte (num/1000);
                        break;
                case 1: ans = Convert.ToByte ((num/100)%10);
                        break;
                case 2: ans = Convert.ToByte ((num/10)%10);
                        break;
                case 3: ans = Convert.ToByte (num%10);
                        break;
                }
            }
        Console.WriteLine (ans);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int K = cin.nextint;
        for (int i = 1; ; i++)
        {
            var S = i.ToString();
            if (K <= S.Length)
            {
                WriteLine(S[K - 1]);
                return;
            }

            K -= S.Length;
        }
    }

}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CF2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "";
            for (int i = 1; i < 10000; i++)
            {
                s += Convert.ToString(i);
            }
            int k = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(s[k - 1]);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Text;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var k = input.ReadLong();
      if (k < 10)
      {
        Console.Write(k);
      }
      else
      {
        var d = 1;
        long a = 0;
        long b = 9;
        while (a + b * d < k)
        {
          a += b * d;
          b *= 10;
          d++;
        }
        var x = (long)Math.Pow(10, d - 1);
        var c = (k - a - 1) / d;
        var y = x + c;
        var j = (k - a - 1) % d;
        for (var i = 0; i < d - j - 1; i++)
        {
          y /= 10;
        }
        Console.Write(y % 10);
      }
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      var result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        var K = cin.nextlong - 1;

        long now = 1;
        for (int i = 1; ; i++)
        {
            //長さがiの数字の数 [10..0, 100..0)
            long len = now * 10 - now;

            long cnt = i * len;
            if (K < cnt)
            {
                //何個目の数字か
                var idx = K / i;
                //何番目の文字か
                var t = K % i;
                //数字はなにか
                var num = now + idx;

                //WriteLine(idx + " " + t + "  " + K + " " + len + " " + num);

                WriteLine((now + idx).ToString()[(int)t]);
                return;
            }

            now *= 10;
            K -= cnt;
        }
    }

}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}

using System;
namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "1";
            int n;

            for(n=2;n<=10000;n++)
            {
                a += Convert.ToString(n);
            }

            int k = Convert.ToInt32(Console.ReadLine());
            char[] b = a.ToCharArray();
            Console.WriteLine(b[k-1]);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Text;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var k = input.ReadLong();
      var d = 1;
      long a = 0;
      long b = 9;
      while (a + b * d < k)
      {
        a += b * d;
        if (a + b * d <= k)
        {
          b *= 10;
          d++;
        }
      }
      var x = (long)Math.Pow(10, d - 1);
      var c = (k - a - 1) / d;
      var y = x + c;
      var j = (k - a - 1) % d;
      for (var i = 0; i < d - j - 1; i++)
      {
        y /= 10;
      }
      Console.Write(y % 10);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      var result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Globalization;
using System.IO;
using System.Text;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var k = input.ReadLong() - 1;
      var d = 1;
      long a = 0;
      long b = 9;
      while (a + b <= k)
      {
        a += b;
        b *= 10;
        d++;
      }
      var x = (long)Math.Pow(10, d - 1);
      var c = (k - a) / d;
      var y = x + c;
      var j = (k - a) % d;
      for (var i = 0; i < d - j - 1; i++)
      {
        y /= 10;
      }
      Console.Write(y % 10);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      var result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Globalization;
using System.IO;
using System.Text;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var k = input.ReadLong();
      var d = 1;
      long a = 0;
      long b = 9;
      while (a + b * d <= k)
      {
        a += b * d;
        if (a + b * d <= k)
        {
          b *= 10;
          d++;
        }
      }
      var x = (long)Math.Pow(10, d - 1);
      var c = (k - a - 1) / d;
      var y = x + c;
      var j = (k - a - 1) % d;
      for (var i = 0; i < d - j - 1; i++)
      {
        y /= 10;
      }
      Console.Write(y % 10);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      var result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
class Program
{
    static void Main(){
        var n = int.Parse(Console.ReadLine());
            var str = "";
            for(int i = 1; i<5000; i++)
            {
                str += i.ToString();
            }
            Console.WriteLine(str[n]);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int N, M;
        sc.Make(out N, out M);
        int[] res = new int[N],ex=new int[N];
        int[] ct = new int[M],ts=new int[M];

        var pq = new PriorityQueue<Pi>((a,b)=>a.v1-b.v1);
        for(var i = 0; i < M; i++)
        {
            int s, t, c;
            sc.Make(out s, out t, out c);
            s--;t--;
            res[t] = M+1;
            ts[i] = t;
            ex[t] = i;
            pq.Push(new Pi(s,i));
            ct[i] = c;
        }
        var f = new PriorityQueue<Pair<int,int,int>>((a, b) => a.v1 - b.v1);
        var use = new bool[M];
        for(var i = 0; i < N; i++)
        {
            while (pq.Any() && pq.Top.v1 == i)
                f.Push(new Pair<int,int,int>(ts[pq.Top.v2], ct[pq.Top.v2],pq.Pop().v2));
            if (res[i] == M+1)
            {
                if (!use[ex[i]]) Fail(-1);
                continue;
            }
            if (!f.Any()) continue;
            var p = f.Pop();
            res[i] = p.v3+1;
            p.v2--;
            if (p.v2 != 0) f.Push(p);
            else use[p.v3] = true;
        }

        Console.WriteLine(string.Join(" ", res));

    }
}

public class PriorityQueue<T>
{
    private List<T> data = new List<T>();
    private Comparison<T> cmp;
    public int Count { get { return data.Count; } }
    public T Top { get { return data[0]; } }
    public PriorityQueue() { cmp = cmp ?? Comparer<T>.Default.Compare; }

    public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private int Parent(int i)
        => (i - 1) >> 1;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private int Left(int i)
        => (i << 1) + 1;
    public T Push(T val)
    {
        int i = data.Count;
        data.Add(val);
        while (i > 0)
        {
            int p = Parent(i);
            if (cmp(data[p], val) <= 0)
                break;
            data[i] = data[p];
            i = p;
        }
        data[i] = val;
        return val;
    }
    public T Pop()
    {
        var ret = data[0];
        var p = 0;
        var x = data[data.Count - 1];
        while (Left(p) < data.Count - 1)
        {
            var l = Left(p);
            if (l < data.Count - 2 && cmp(data[l + 1], data[l]) < 0) l++;
            if (cmp(data[l], x) >= 0)
                break;
            data[p] = data[l];
            p = l;
        }
        data[p] = x;
        data.RemoveAt(data.Count - 1);
        return ret;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public bool Any() => data.Count > 0;
}
#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static T[] Copy<T>(this T[] A)
        => Create(A.Length, i => A[i]);
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Collections;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();

        int[] s = new int[m];
        int[] d = new int[m];
        int[] c = new int[m];

        for (int i = 0; i < m; i++)
        {
            s[i] = sc.NextInt() - 1;
            d[i] = sc.NextInt() - 1;
            c[i] = sc.NextInt();
        }

        // i日に公開される試験
        List<int>[] l = new List<int>[n];

        // i日にある試験
        int[] r = new int[n];
        for (int i = 0; i < n; i++)
        {
            l[i] = new List<int>();
            r[i] = -1;
        }

        for (int i = 0; i < m; i++)
        {
            l[s[i]].Add(i);
            r[d[i]] = i;
        }

        // 試験iへの勉強日数
        int[] cnt = new int[m];
        var pq = new PriorityQueue<int>((l, r) => d[l].CompareTo(d[r]));

        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
        {
            foreach (int j in l[i])
            {
                pq.Enqueue(j);
            }

            if (r[i] == -1)
            {
                if (pq.Count <= 0) continue;
                var peek = pq.Peek();
                cnt[peek]++;
                ans[i] = peek + 1;
                if (cnt[peek] >= c[peek]) pq.Dequeue();
            }
            else
            {
                if (cnt[r[i]] < c[r[i]])
                {
                    Console.WriteLine("-1");
                    return;
                }

                ans[i] = m + 1;
            }
        }

        Console.WriteLine(string.Join(" ", ans));
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Collections
{
    using System;
    using System.Collections.Generic;

    #region PriorityQueue

    /// <summary>
    /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します．
    /// </summary>
    /// <typeparam name="T">優先度付きキュー内の要素の型を指定します．</typeparam>
    /// <remarks>内部的にはバイナリヒープによって実装されています．</remarks>
    public class PriorityQueue<T>
    {
        readonly List<T> heap = new List<T>();
        readonly Comparison<T> cmp;

        /// <summary>
        /// デフォルトの比較子を使用してインスタンスを初期化します．
        /// </summary>
        /// <remarks>この操作は O(1) で実行されます．</remarks>
        public PriorityQueue()
        {
            cmp = Comparer<T>.Default.Compare;
        }

        /// <summary>
        /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します．
        /// </summary>
        /// <param name="comparison"></param>
        /// <remarks>この操作は O(1) で実行されます．</remarks>
        public PriorityQueue(Comparison<T> comparison)
        {
            cmp = comparison;
        }

        /// <summary>
        /// 指定された比較子を使用してインスタンスを初期化します．
        /// </summary>
        /// <param name="comparer"></param>
        /// <remarks>この操作は O(1) で実行されます．</remarks>
        public PriorityQueue(IComparer<T> comparer)
        {
            cmp = comparer.Compare;
        }

        /// <summary>
        /// 優先度付きキューに要素を追加します．
        /// </summary>
        /// <param name="item">優先度付きキューに追加される要素</param>
        /// <remarks>最悪計算量 O(log N) で実行されます．</remarks>
        public void Enqueue(T item)
        {
            var pos = heap.Count;
            heap.Add(item);
            while (pos > 0)
            {
                var par = (pos - 1) / 2;
                if (cmp(heap[par], item) <= 0)
                    break;
                heap[pos] = heap[par];
                pos = par;
            }

            heap[pos] = item;
        }

        /// <summary>
        /// 優先度付きキューから最も価値が低い要素を削除し，返します．
        /// </summary>
        /// <returns>優先度付きキューから削除された要素．</returns>
        /// <remarks>最悪計算量 O(log N) で実行されます．</remarks>
        public T Dequeue()
        {
            var ret = heap[0];
            var pos = 0;
            var x = heap[heap.Count - 1];

            while (pos * 2 + 1 < heap.Count - 1)
            {
                var lch = pos * 2 + 1;
                var rch = pos * 2 + 2;
                if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch;
                if (cmp(heap[lch], x) >= 0)
                    break;
                heap[pos] = heap[lch];
                pos = lch;
            }

            heap[pos] = x;
            heap.RemoveAt(heap.Count - 1);
            return ret;
        }

        /// <summary>
        ///  優先度付きキューに含まれる最も価値が低い要素を削除せずに返します．
        /// </summary>
        /// <returns>優先度付きキューに含まれる最も価値が低い要素．</returns>
        /// <remarks>この操作は O(1) で実行されます．</remarks>
        public T Peek()
        {
            return heap[0];
        }

        /// <summary>
        /// 優先度付きキュー内の要素の数を取得します．
        /// </summary>
        /// <returns>優先度付キュー内にある要素の数</returns>
        /// <remarks>最悪計算量 O(1) で実行されます．</remarks>
        public int Count
        {
            get { return heap.Count; }
        }

        /// <summary>
        /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します．
        /// </summary>
        /// <returns>優先度付キュー内にある要素が存在するならば true，そうでなければ　false．</returns>
        /// <remarks>この操作は O(1) で実行されます．</remarks>
        public bool Any()
        {
            return heap.Count > 0;
        }

        /// <summary>
        /// 優先度付きキューに含まれる要素を昇順に並べて返します．
        /// </summary>
        /// <remarks>この操作は計算量 O(N log N)で実行されます．</remarks>
        public T[] Items
        {
            get
            {
                var ret = heap.ToArray();
                Array.Sort(ret, cmp);
                return ret;
            }
        }
    }

    #endregion
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CodeforcesRound481Div3.Questions;
using System.Diagnostics.CodeAnalysis;

namespace CodeforcesRound481Div3.Questions
{
    public class QuestionG : AtCoderQuestionBase
    {
        public override void Solve(IOManager io)
        {
            var totalDays = io.ReadInt();
            var totalExams = io.ReadInt();
            var result = new int[totalDays];
            var starts = Enumerable.Repeat(0, totalDays).Select(_ => new List<int>()).ToArray();
            var exams = new Exam[totalExams];
            var examPlans = new int[totalDays];

            for (int i = 0; i < exams.Length; i++)
            {
                var s = io.ReadInt() - 1;
                var d = io.ReadInt() - 1;
                var c = io.ReadInt();
                exams[i] = new Exam(d, i);

                for (int j = 0; j < c; j++)
                {
                    starts[s].Add(i);
                }

                result[d] = totalExams + 1;
                examPlans[d] = i;
            }

            Array.Sort(exams);
            Study.SetOrder(exams.Select(ex => ex.ID).ToArray());
            var queue = new PriorityQueue<Study>(false);
            var ended = new HashSet<int>();

            for (int day = 0; day < result.Length; day++)
            {
                foreach (var todo in starts[day])
                {
                    queue.Enqueue(new Study(todo));
                }

                if (result[day] == 0 && queue.Count > 0)
                {
                    var next = queue.Dequeue().Subject;
                    if (ended.Contains(next))
                    {
                        io.WriteLine(-1);
                        return;
                    }
                    else
                    {
                        result[day] = next + 1;
                    }
                }
                else if (result[day] != 0)
                {
                    ended.Add(examPlans[day]);
                }
            }

            if (queue.Count == 0)
            {
                io.WriteLine(result, ' ');
            }
            else
            {
                io.WriteLine(-1);
            }
        }

        [StructLayout(LayoutKind.Auto)]
        readonly struct Exam : IComparable<Exam>
        {
            public int EndDay { get; }
            public int ID { get; }

            public Exam(int endDay, int id)
            {
                EndDay = endDay;
                ID = id;
            }

            public void Deconstruct(out int endDay, out int id) => (endDay, id) = (EndDay, ID);
            public override string ToString() => $"{nameof(EndDay)}: {EndDay}, {nameof(ID)}: {ID}";

            public int CompareTo([AllowNull] Exam other) => EndDay - other.EndDay;
        }

        readonly struct Study : IComparable<Study>
        {
            public int Subject { get; }
            static int[] _order;

            public static void SetOrder(int[] subjects)
            {
                _order = new int[subjects.Length];

                for (int i = 0; i < subjects.Length; i++)
                {
                    _order[subjects[i]] = i;
                }
            }

            public Study(int subject)
            {
                Subject = subject;
            }

            public int CompareTo([AllowNull] Study other) => _order[Subject] - _order[other.Subject];
        }
    }

    public class PriorityQueue<T> : IEnumerable<T> where T : IComparable<T>
    {
        private List<T> _heap = new List<T>();
        private readonly int _reverseFactor;
        public int Count => _heap.Count;
        public bool IsDescending => _reverseFactor == 1;

        public PriorityQueue(bool descending) : this(descending, null) { }

        public PriorityQueue(bool descending, IEnumerable<T> collection)
        {
            _reverseFactor = descending ? 1 : -1;
            _heap = new List<T>();

            if (collection != null)
            {
                foreach (var item in collection)
                {
                    Enqueue(item);
                }
            }
        }

        public void Enqueue(T item)
        {
            _heap.Add(item);
            UpHeap();
        }

        public T Dequeue()
        {
            var item = _heap[0];
            DownHeap();
            return item;
        }

        public T Peek() => _heap[0];

        private void UpHeap()
        {
            var child = Count - 1;
            while (child > 0)
            {
                int parent = (child - 1) / 2;

                if (Compare(_heap[child], _heap[parent]) > 0)
                {
                    SwapAt(child, parent);
                    child = parent;
                }
                else
                {
                    break;
                }
            }
        }

        private void DownHeap()
        {
            _heap[0] = _heap[Count - 1];
            _heap.RemoveAt(Count - 1);

            var parent = 0;
            while (true)
            {
                var leftChild = 2 * parent + 1;

                if (leftChild > Count - 1)
                {
                    break;
                }

                var target = (leftChild < Count - 1) && (Compare(_heap[leftChild], _heap[leftChild + 1]) < 0) ? leftChild + 1 : leftChild;

                if (Compare(_heap[parent], _heap[target]) < 0)
                {
                    SwapAt(parent, target);
                }
                else
                {
                    break;
                }

                parent = target;
            }
        }

        private int Compare(T a, T b) => _reverseFactor * a.CompareTo(b);

        private void SwapAt(int n, int m) => (_heap[n], _heap[m]) = (_heap[m], _heap[n]);

        public IEnumerator<T> GetEnumerator()
        {
            var copy = new List<T>(_heap);
            try
            {
                while (Count > 0)
                {
                    yield return Dequeue();
                }
            }
            finally
            {
                _heap = copy;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
    }

}

namespace CodeforcesRound481Div3
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionG();
            using var io = new IOManager(Console.OpenStandardInput(), Console.OpenStandardOutput());
            question.Solve(io);
        }
    }
}

#region Base Class

namespace CodeforcesRound481Div3.Questions
{

    public interface IAtCoderQuestion
    {
        string Solve(string input);
        void Solve(IOManager io);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public string Solve(string input)
        {
            var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(input));
            var outputStream = new MemoryStream();
            using var manager = new IOManager(inputStream, outputStream);

            Solve(manager);
            manager.Flush();

            outputStream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(outputStream);
            return reader.ReadToEnd();
        }

        public abstract void Solve(IOManager io);
    }

    public class IOManager : IDisposable
    {
        private readonly StreamReader _reader;
        private readonly StreamWriter _writer;
        private bool _disposedValue;
        private Queue<ReadOnlyMemory<char>> _stringQueue;

        const char ValidFirstChar = '!';
        const char ValidLastChar = '~';

        public IOManager(Stream input, Stream output)
        {
            _reader = new StreamReader(input);
            _writer = new StreamWriter(output) { AutoFlush = false };
            _stringQueue = new Queue<ReadOnlyMemory<char>>();
        }

        public ReadOnlySpan<char> ReadCharSpan()
        {
            while (_stringQueue.Count == 0)
            {
                var line = _reader.ReadLine().AsMemory().Trim();
                var s = line.Span;

                if (s.Length > 0)
                {
                    var begin = 0;
                    for (int i = 0; i < s.Length; i++)
                    {
                        if (begin < 0 && IsValidChar(s[i]))
                        {
                            begin = i;
                        }
                        else if (!IsValidChar(s[i]))
                        {
                            _stringQueue.Enqueue(line[begin..i]);
                            begin = -1;
                        }
                    }
                    _stringQueue.Enqueue(line[begin..line.Length]);
                }
            }

            return _stringQueue.Dequeue().Span;
        }

        public string ReadString() => ReadCharSpan().ToString();

        public int ReadInt() => (int)ReadLong();

        public long ReadLong()
        {
            long result = 0;
            bool isPositive = true;

            int i = 0;
            var s = ReadCharSpan();
            if (s[i] == '-')
            {
                isPositive = false;
                i++;
            }

            while (i < s.Length)
            {
                result = result * 10 + (s[i++] - '0');
            }

            return isPositive ? result : -result;
        }

        public double ReadDouble() => double.Parse(ReadCharSpan());
        public decimal ReadDecimal() => decimal.Parse(ReadCharSpan());

        public int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }

        public long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }

        public double[] ReadDoubleArray(int n)
        {
            var a = new double[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadDouble();
            }
            return a;
        }

        public decimal[] ReadDecimalArray(int n)
        {
            var a = new decimal[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = ReadDecimal();
            }
            return a;
        }

        public void WriteLine<T>(T value) => _writer.WriteLine(value.ToString());

        public void WriteLine<T>(IEnumerable<T> values, char separator)
        {
            var e = values.GetEnumerator();
            if (e.MoveNext())
            {
                _writer.Write(e.Current.ToString());

                while (e.MoveNext())
                {
                    _writer.Write(separator);
                    _writer.Write(e.Current.ToString());
                }
            }

            _writer.WriteLine();
        }

        public void Flush() => _writer.Flush();

        private static bool IsValidChar(char c) => ValidFirstChar <= c && c <= ValidLastChar;

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _reader.Dispose();
                    _writer.Flush();
                    _writer.Dispose();
                }

                _disposedValue = true;
            }
        }

        public void Dispose()
        {
            Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }
    }
}

#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace G
{
    class Program
    {
        static void Main(string[] args)
        {
            //StreamReader sr = new StreamReader("in10.txt");
            TextReader sr = Console.In;
            string[] ss = sr.ReadLine().Split();
            int n = Convert.ToInt32(ss[0]);
            int m = Convert.ToInt32(ss[1]);
            int[] res = new int[n];
            int[] vozm_d_count = new int[m];//кол-во возомжные дни для подготовки к экзамену i
            int[] budet_d_count = new int[m];//кол-во дни выделенных для подготовки к экзамену i
            int[] vozm_ekz_count = new int[n];//кол-во возомжныех экзмаенов для подготовки в день i
            int[,] vozm = new int[m, n];
            int[] s = new int[m], d = new int[m], c = new int[m];
            for (int i = 0; i < m; i++)
            {
                ss = sr.ReadLine().Split();
                s[i] = Convert.ToInt32(ss[0]);
                d[i] = Convert.ToInt32(ss[1]);
                c[i] = Convert.ToInt32(ss[2]);
                for (int j = s[i] - 1; j < d[i]; j++)
                {
                    if (vozm[i, j] != 3)//в этот день петя не сдает экзамен
                    {
                        vozm[i, j] = 1;//в день j петя может готовитья к экзамену i
                        vozm_ekz_count[j]++;
                        vozm_d_count[i]++;
                    }
                }
                for (int j = 0; j < m; j++)
                {
                    if (vozm[j, d[i] - 1] == 1)//в этот день d[i] петя планировал готовиться к экзмаену j
                    {
                        vozm_ekz_count[d[i] - 1]--;
                        vozm_d_count[j]--;
                    }
                    vozm[j, d[i] - 1] = 3;//в день d[i] петя может готовитья к экзамену j
                }
                res[d[i] - 1] = m + 1;
            }
            //решение
            bool can = true;
            bool is0 = true;
            bool finish = true;
            while (true)
            {
                is0 = true;
                finish = true;
                for (int j = 0; j < n; j++)
                {
                    if (vozm_ekz_count[j] == 1)
                    {
                        finish = false;
                        for (int i = 0; i < m; i++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                if (budet_d_count[i] < c[i])
                                {
                                    vozm[i, j] = 2;
                                    vozm_d_count[i]--;
                                    budet_d_count[i]++;
                                    res[j] = i + 1;
                                    if (budet_d_count[i] == c[i])
                                    {
                                        for (int j1 = 0; j1 < n; j1++)
                                        {
                                            if (vozm[i, j1] == 1/*j != j1*/)
                                            {
                                                vozm[i, j1] = 0;
                                                vozm_ekz_count[j1]--;
                                            }
                                        }
                                        vozm_d_count[i] = 0;
                                        budet_d_count[i] = c[i];
                                    }
                                }
                                else
                                {
                                    vozm[i, j] = 0;
                                    vozm_d_count[i]--;
                                }
                            }
                        }
                        vozm_ekz_count[j] = 0;
                        is0 = false;
                    }
                    else if (vozm_ekz_count[j] > 1)
                        finish = false;
                }

                for (int i = 0; i < m; i++)
                {
                    if (/*budet_d_count[i]< c[i] &&*/vozm_d_count[i] > 0 && vozm_d_count[i] + budet_d_count[i] == c[i])
                    {
                        finish = false;
                        for (int j = 0; j < n; j++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                res[j] = i + 1;
                                for (int i1 = 0; i1 < m; i1++)
                                {
                                    if (i1 != i)
                                    {
                                        if (vozm[i1, j] == 2)
                                        {
                                            can = false;
                                            goto metka;
                                        }
                                        if (vozm[i1, j] == 1)
                                        {
                                            vozm[i1, j] = 0;
                                            vozm_d_count[i1]--;
                                        }
                                    }
                                }
                                vozm_ekz_count[j] = 0;
                            }
                        }
                        vozm_d_count[i] = 0;
                        budet_d_count[i] = c[i];
                        is0 = false;
                    }
                    else
                    {
                        if (vozm_d_count[i] > 0)
                            finish = false;
                        if (vozm_d_count[i] + budet_d_count[i] < c[i])
                        {
                            can = false;
                            goto metka;
                        }
                    }
                }

                //if (is0) break;
                if (finish) break;
                else if (is0)
                {
                    //выбрать случайный день для подготовки
                    for (int j = n - 1; j >= 0; j--)
                    {
                        if (vozm_ekz_count[j] > 1)
                        {
                            int iv = -1;
                            for (int i = 0; i < m; i++)
                            {
                                if (vozm[i, j] == 1)
                                {
                                    if (iv == -1) iv = i;
                                    else
                                    {
                                        if ((vozm_d_count[iv]-(c[iv]- budet_d_count[iv]))> (vozm_d_count[i] - (c[i] - budet_d_count[i]))) iv = i;
                                    }
                                }
                            }
                            //пометить выбранный день
                            if (c[iv] > budet_d_count[iv])
                            {
                                vozm[iv, j] = 2;
                                res[j] = iv + 1;
                                for (int i = 0; i < m; i++)
                                {
                                    if (vozm[i, j] == 1)
                                    {
                                        vozm[i, j] = 0;
                                        vozm_d_count[i]--;
                                    }
                                }
                                vozm_ekz_count[j] = 0;
                                budet_d_count[iv]++;
                                vozm_d_count[iv]--;
                                break;
                            }
                            else
                            {
                                vozm[iv, j] = 0;
                                vozm_ekz_count[j] --;
                                vozm_d_count[iv]--;
                                break;
                            }
                        }
                    }
                }
            }

            metka:
            //вывод решения
            if (can) Console.WriteLine(string.Join(" ", res));
            else Console.WriteLine("-1");

        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Petya_s_Exams
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            Solve(args);
            writer.Flush();
        }

        private static void Solve(string[] args)
        {
            int n = Next();
            int m = Next();

            var nn = new int[n];

            var s = new int[m];
            var d = new int[m];
            var c = new int[m];
            var indx = new int[m];
            for (int i = 0; i < m; i++)
            {
                s[i] = Next();
                d[i] = Next();
                c[i] = Next();
                indx[i] = i;

                nn[d[i] - 1] = m + 1;
            }
            Array.Sort(d, indx);

            for (int i = 0; i < m; i++)
            {
                int index = indx[i];
                for (int j = s[index] - 1; j < d[i]; j++)
                {
                    if (nn[j] == 0)
                    {
                        nn[j] = index + 1;
                        c[index]--;
                        if (c[index] == 0)
                            break;
                    }
                }
                if (c[index] != 0)
                {
                    writer.WriteLine("-1");
                    return;
                }
            }

            foreach (int i in nn)
            {
                writer.Write(i);
                writer.Write(' ');
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace Petya_Exam
{
    class Program
    {
        struct Exam
        {
            public int ExamIndex;
            public int Publish;
            public int ExamDay;
            public int PrepDays;
        }

        static void Main(string[] args)
        {
            List<Exam> list2 = new List<Exam>();
            int N_Days;
            int Total_exams;

                string[] s = (Console.ReadLine()).Split(' ');
                N_Days = int.Parse(s[0]);
                Total_exams = int.Parse(s[1]);

                for (int i = 0; i < Total_exams; ++i)
                {
                    Exam exm;
                    s = (Console.ReadLine()).Split(' ');
                    exm.ExamIndex = i + 1;
                    exm.Publish = int.Parse(s[0]);
                    exm.ExamDay = int.Parse(s[1]);
                    exm.PrepDays = int.Parse(s[2]);
                    list2.Add(exm);
                }

           list2.Sort((x, y) => x.ExamDay.CompareTo(y.ExamDay));
            List<int> seq = new List<int>();
            for (int i = 0; i <= N_Days; ++i)
            {
                seq.Add(0);
            }
            int print = 0;
            foreach (Exam l in list2)
            {
                if (l.Publish - 1 + l.PrepDays < l.ExamDay)
                {
                    if (Ispossible(l.ExamIndex, l, seq))
                    {
                        seq[l.ExamDay] = Total_exams + 1;

                        continue;
                    }
                    else
                    {
                        print = -1;
                        break;
                    }
                }
                else
                {
                    print = -1;
                    break;
                }
            }
            if (print == 0)
            {
                if (seq.Sum() != 0)
                {
                    for (int j = 1; j < seq.Count; ++j)
                    {
                        if (j + 1 == seq.Count)
                        {
                            Console.Write(seq[j]);
                            continue;
                        }
                        Console.Write(seq[j] + " ");
                    }
                }
                else
                {
                    Console.WriteLine("-1");
                }
            }
            else
            {
                Console.WriteLine("-1");
            }

            //Console.ReadKey();
        }

        private static bool Ispossible(int exam_number, Exam l, List<int> seq)
        {
            int days = l.PrepDays;

            int i = l.Publish;
            while (i < l.ExamDay && days > 0)
            {
                if (seq[i] == 0)
                {
                    seq[i] = exam_number;
                    days--;
                }
                i++;
            }
            return days == 0 ? true : false;
        }

    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace G
{
    class Program
    {
        static void Main(string[] args)
        {
            //StreamReader sr = new StreamReader("in2.txt");
            TextReader sr = Console.In;
            string[] ss = sr.ReadLine().Split();
            int n = Convert.ToInt32(ss[0]);
            int m = Convert.ToInt32(ss[1]);
            int[] res = new int[n];
            int[] vozm_d_count = new int[m];//кол-во возомжные дни для подготовки к экзамену i
            int[] budet_d_count = new int[m];//кол-во дни выделенных для подготовки к экзамену i
            int[] vozm_ekz_count = new int[n];//кол-во возомжныех экзмаенов для подготовки в день i
            int[,] vozm = new int[m, n];
            int[] s = new int[m], d = new int[m], c = new int[m];
            for (int i = 0; i < m; i++)
            {
                ss = sr.ReadLine().Split();
                s[i] = Convert.ToInt32(ss[0]);
                d[i] = Convert.ToInt32(ss[1]);
                c[i] = Convert.ToInt32(ss[2]);
                for (int j = s[i] - 1; j < d[i]; j++)
                {
                    if (vozm[i, j] != 3)//в этот день петя не сдает экзамен
                    {
                        vozm[i, j] = 1;//в день j петя может готовитья к экзамену i
                        vozm_ekz_count[j]++;
                        vozm_d_count[i]++;
                    }
                }
                for (int j = 0; j < m; j++)
                {
                    if (vozm[j, d[i] - 1] == 1)//в этот день d[i] петя планировал готовиться к экзмаену j
                    {
                        vozm_ekz_count[d[i] - 1]--;
                        vozm_d_count[j]--;
                    }
                    vozm[j, d[i] - 1] = 3;//в день d[i] петя может готовитья к экзамену j
                }
                res[d[i] - 1] = m + 1;
            }
            //решение
            bool can = true;
            bool is0 = true;
            while (true)
            {
                is0 = true;

                for (int j = 0; j < n; j++)
                {
                    if (vozm_ekz_count[j] == 1)
                    {
                        for (int i = 0; i < m; i++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                vozm_d_count[i]--;
                                budet_d_count[i]++;
                                res[j] = i + 1;
                                if (budet_d_count[i] == c[i])
                                {
                                    for (int j1 = 0; j1 < n; j1++)
                                    {
                                        if (vozm[i, j1]==1/*j != j1*/)
                                        {
                                            vozm[i, j1] = 0;
                                            vozm_ekz_count[j1]--;
                                        }
                                    }
                                    vozm_d_count[i] = 0;
                                    budet_d_count[i] = c[i];
                                }
                            }
                        }
                        vozm_ekz_count[j] = 0;
                        is0 = false;
                    }
                }

                for (int i = 0; i < m; i++)
                {
                    if (/*budet_d_count[i]< c[i] &&*/vozm_d_count[i] > 0 && vozm_d_count[i] + budet_d_count[i] == c[i])
                    {
                        for (int j = 0; j < n; j++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                for (int i1 = 0; i1 < m; i1++)
                                {
                                    if (i1 != i)
                                    {
                                        if (vozm[i1, j] == 2)
                                        {
                                            can = false;
                                            goto metka;
                                        }
                                        vozm[i1, j] = 0;
                                        vozm_d_count[i1]--;
                                    }
                                }
                                vozm_ekz_count[j] = 0;
                            }
                        }
                        vozm_d_count[i] = 0;
                        budet_d_count[i] = c[i];
                        is0 = false;
                    }
                    else
                    {
                        if (vozm_d_count[i] + budet_d_count[i] < c[i])
                        {
                            can = false;
                            goto metka;
                        }
                    }
                }

                if (is0) break;
            }

            metka:
            //вывод решения
            if (can) Console.WriteLine(string.Join(" ", res));
            else Console.WriteLine("-1");

        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace G
{
    class Program
    {
        static void Main(string[] args)
        {
            //StreamReader sr = new StreamReader("in10.txt");
            TextReader sr = Console.In;
            string[] ss = sr.ReadLine().Split();
            int n = Convert.ToInt32(ss[0]);
            int m = Convert.ToInt32(ss[1]);
            int[] res = new int[n];
            int[] vozm_d_count = new int[m];//кол-во возомжные дни для подготовки к экзамену i
            int[] budet_d_count = new int[m];//кол-во дни выделенных для подготовки к экзамену i
            int[] vozm_ekz_count = new int[n];//кол-во возомжныех экзмаенов для подготовки в день i
            int[,] vozm = new int[m, n];
            int[] s = new int[m], d = new int[m], c = new int[m];
            for (int i = 0; i < m; i++)
            {
                ss = sr.ReadLine().Split();
                s[i] = Convert.ToInt32(ss[0]);
                d[i] = Convert.ToInt32(ss[1]);
                c[i] = Convert.ToInt32(ss[2]);
                for (int j = s[i] - 1; j < d[i]; j++)
                {
                    if (vozm[i, j] != 3)//в этот день петя не сдает экзамен
                    {
                        vozm[i, j] = 1;//в день j петя может готовитья к экзамену i
                        vozm_ekz_count[j]++;
                        vozm_d_count[i]++;
                    }
                }
                for (int j = 0; j < m; j++)
                {
                    if (vozm[j, d[i] - 1] == 1)//в этот день d[i] петя планировал готовиться к экзмаену j
                    {
                        vozm_ekz_count[d[i] - 1]--;
                        vozm_d_count[j]--;
                    }
                    vozm[j, d[i] - 1] = 3;//в день d[i] петя может готовитья к экзамену j
                }
                res[d[i] - 1] = m + 1;
            }
            //решение
            bool can = true;
            bool is0 = true;
            bool finish = true;
            while (true)
            {
                is0 = true;
                finish = true;
                for (int j = 0; j < n; j++)
                {
                    if (vozm_ekz_count[j] == 1)
                    {
                        finish = false;
                        for (int i = 0; i < m; i++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                vozm_d_count[i]--;
                                budet_d_count[i]++;
                                res[j] = i + 1;
                                if (budet_d_count[i] == c[i])
                                {
                                    for (int j1 = 0; j1 < n; j1++)
                                    {
                                        if (vozm[i, j1] == 1/*j != j1*/)
                                        {
                                            vozm[i, j1] = 0;
                                            vozm_ekz_count[j1]--;
                                        }
                                    }
                                    vozm_d_count[i] = 0;
                                    budet_d_count[i] = c[i];
                                }
                            }
                        }
                        vozm_ekz_count[j] = 0;
                        is0 = false;
                    }
                    else if (vozm_ekz_count[j] > 1)
                        finish = false;
                }

                for (int i = 0; i < m; i++)
                {
                    if (/*budet_d_count[i]< c[i] &&*/vozm_d_count[i] > 0 && vozm_d_count[i] + budet_d_count[i] == c[i])
                    {
                        finish = false;
                        for (int j = 0; j < n; j++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                res[j] = i + 1;
                                for (int i1 = 0; i1 < m; i1++)
                                {
                                    if (i1 != i)
                                    {
                                        if (vozm[i1, j] == 2)
                                        {
                                            can = false;
                                            goto metka;
                                        }
                                        if (vozm[i1, j] == 1)
                                        {
                                            vozm[i1, j] = 0;
                                            vozm_d_count[i1]--;
                                        }
                                    }
                                }
                                vozm_ekz_count[j] = 0;
                            }
                        }
                        vozm_d_count[i] = 0;
                        budet_d_count[i] = c[i];
                        is0 = false;
                    }
                    else
                    {
                        if (vozm_d_count[i] > 0)
                            finish = false;
                        if (vozm_d_count[i] + budet_d_count[i] < c[i])
                        {
                            can = false;
                            goto metka;
                        }
                    }
                }

                //if (is0) break;
                if (finish) break;
                else if (is0)
                {
                    //выбрать случайный день для подготовки
                    for (int j = n - 1; j >= 0; j--)
                    {
                        if (vozm_ekz_count[j] > 1)
                        {
                            int iv = -1;
                            for (int i = 0; i < m; i++)
                            {
                                if (vozm[i, j] == 1)
                                {
                                    if (iv == -1) iv = i;
                                    else
                                    {
                                        if ((vozm_d_count[i]-(c[i]- budet_d_count[i]))> (vozm_d_count[i] - (c[i] - budet_d_count[i]))) iv = i;
                                    }
                                }
                            }
                            //пометить выбранный день
                            vozm[iv, j] = 2;
                            res[j] = iv + 1;
                            for (int i = 0; i < m; i++)
                            {
                                if (vozm[i, j] == 1)
                                {
                                    vozm[i, j] = 0;
                                    vozm_d_count[i]--;
                                }
                            }
                            vozm_ekz_count[j] = 0;
                            budet_d_count[iv]++;
                            vozm_d_count[iv]--;
                            break;
                        }
                    }
                }
            }

            metka:
            //вывод решения
            if (can) Console.WriteLine(string.Join(" ", res));
            else Console.WriteLine("-1");

        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace G
{
    class Program
    {
        static void Main(string[] args)
        {
            //StreamReader sr = new StreamReader("in3.txt");
            TextReader sr = Console.In;
            string[] ss = sr.ReadLine().Split();
            int n = Convert.ToInt32(ss[0]);
            int m = Convert.ToInt32(ss[1]);
            int[] res = new int[n];
            int[] vozm_d_count = new int[m];//кол-во возомжные дни для подготовки к экзамену i
            int[] budet_d_count = new int[m];//кол-во дни выделенных для подготовки к экзамену i
            int[] vozm_ekz_count = new int[n];//кол-во возомжныех экзмаенов для подготовки в день i
            int[,] vozm = new int[m, n];
            int[] s = new int[m], d = new int[m], c = new int[m];
            for (int i = 0; i < m; i++)
            {
                ss = sr.ReadLine().Split();
                s[i] = Convert.ToInt32(ss[0]);
                d[i] = Convert.ToInt32(ss[1]);
                c[i] = Convert.ToInt32(ss[2]);
                for (int j = s[i] - 1; j < d[i]; j++)
                {
                    if (vozm[i, j] != 3)//в этот день петя не сдает экзамен
                    {
                        vozm[i, j] = 1;//в день j петя может готовитья к экзамену i
                        vozm_ekz_count[j]++;
                        vozm_d_count[i]++;
                    }
                }
                for (int j = 0; j < m; j++)
                {
                    if (vozm[j, d[i] - 1] == 1)//в этот день d[i] петя планировал готовиться к экзмаену j
                    {
                        vozm_ekz_count[d[i] - 1]--;
                        vozm_d_count[j]--;
                    }
                    vozm[j, d[i] - 1] = 3;//в день d[i] петя может готовитья к экзамену j
                }
                res[d[i] - 1] = m + 1;
            }
            //решение
            bool can = true;
            bool is0 = true;
            bool finish = true;
            while (true)
            {
                is0 = true;
                finish = true;
                for (int j = 0; j < n; j++)
                {
                    if (vozm_ekz_count[j] == 1)
                    {
                        finish = false;
                        for (int i = 0; i < m; i++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                vozm_d_count[i]--;
                                budet_d_count[i]++;
                                res[j] = i + 1;
                                if (budet_d_count[i] == c[i])
                                {
                                    for (int j1 = 0; j1 < n; j1++)
                                    {
                                        if (vozm[i, j1] == 1/*j != j1*/)
                                        {
                                            vozm[i, j1] = 0;
                                            vozm_ekz_count[j1]--;
                                        }
                                    }
                                    vozm_d_count[i] = 0;
                                    budet_d_count[i] = c[i];
                                }
                            }
                        }
                        vozm_ekz_count[j] = 0;
                        is0 = false;
                    }
                    else if (vozm_ekz_count[j] > 1)
                        finish = false;
                }

                for (int i = 0; i < m; i++)
                {
                    if (/*budet_d_count[i]< c[i] &&*/vozm_d_count[i] > 0 && vozm_d_count[i] + budet_d_count[i] == c[i])
                    {
                        finish = false;
                        for (int j = 0; j < n; j++)
                        {
                            if (vozm[i, j] == 1)
                            {
                                vozm[i, j] = 2;
                                res[j] = i + 1;
                                for (int i1 = 0; i1 < m; i1++)
                                {
                                    if (i1 != i)
                                    {
                                        if (vozm[i1, j] == 2)
                                        {
                                            can = false;
                                            goto metka;
                                        }
                                        vozm[i1, j] = 0;
                                        vozm_d_count[i1]--;
                                    }
                                }
                                vozm_ekz_count[j] = 0;
                            }
                        }
                        vozm_d_count[i] = 0;
                        budet_d_count[i] = c[i];
                        is0 = false;
                    }
                    else
                    {
                        if (vozm_d_count[i] > 0)
                            finish = false;
                        if (vozm_d_count[i] + budet_d_count[i] < c[i])
                        {
                            can = false;
                            goto metka;
                        }
                    }
                }

                //if (is0) break;
                if (finish) break;
                else if (is0)
                {
                    //выбрать случайный день для подготовки
                    for (int j = n - 1; j >= 0; j--)
                    {
                        if (vozm_ekz_count[j] > 1)
                        {
                            int iv = -1;
                            for (int i = 0; i < m; i++)
                            {
                                if (vozm[i, j] == 1)
                                {
                                    if (iv == -1) iv = i;
                                    else
                                    {
                                        if ((vozm_d_count[i]-(c[i]- budet_d_count[i]))> (vozm_d_count[i] - (c[i] - budet_d_count[i]))) iv = i;
                                    }
                                }
                            }
                            //пометить выбранный день
                            vozm[iv, j] = 2;
                            res[j] = iv + 1;
                            for (int i = 0; i < m; i++)
                            {
                                if (vozm[i, j] == 1)
                                {
                                    vozm[i, j] = 0;
                                    vozm_d_count[i]--;
                                }
                            }
                            vozm_ekz_count[j] = 0;
                            budet_d_count[iv]++;
                            vozm_d_count[iv]--;
                            break;
                        }
                    }
                }
            }

            metka:
            //вывод решения
            if (can) Console.WriteLine(string.Join(" ", res));
            else Console.WriteLine("-1");

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petya_Exam
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine()).Split(' ');
            int N_Days = int.Parse(s[0]);
            int Total_exams = int.Parse(s[1]);
            List<List<int>> list = new List<List<int>>();
            for(int i=0; i<Total_exams; ++i)
            {
                s = (Console.ReadLine()).Split(' ');
                List<int> ls = new List<int>();
                ls.Add(int.Parse(s[0]));
                ls.Add(int.Parse(s[1]));
                ls.Add(int.Parse(s[2]));
                list.Add(ls);
            }
            list = list.OrderBy(ls => ls[1]).ToList();
            List<int> seq = new List<int>();
            for(int i=0; i<=N_Days;++i)
            {
                seq.Add(0);
            }
            int print =0;
            int exam_number = 1;
            foreach(List<int> l in list)
            {
                //int n = l[0];
                if(l[0]-1+l[2]<l[1])
                {
                    if(Ispossible(exam_number,l,seq))
                    {
                        seq[l[1]] = Total_exams + 1;
                        exam_number++;
                        continue;
                    }
                    else
                    {
                        print = -1;
                        break;
                    }
                }
            }
            if(print==0)
            {
                if(seq.Sum()!=0)
                {
                    for (int j = 1; j < seq.Count; ++j)
                    {
                        if (j + 1 == seq.Count)
                        {
                            Console.Write(seq[j]);
                            continue;
                        }
                        Console.Write(seq[j] + " ");
                    }
                }
                else
                {
                    Console.WriteLine("-1");
                }

            }
            else
            {
                Console.WriteLine("-1");
            }

        }

        private static bool Ispossible(int exam_number, List<int> l, List<int> seq)
        {
            int days = l[2];

            int i = l[0];
            while(i<l[1]&& days>0)
            {
                if(seq[i]==0)
                {
                    seq[i] = exam_number;
                    days--;
                }
                i++;
            }
            return days==0?true:false;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petya_Exam
{
    class Program
    {
        struct Exam
        {
            public int ExamIndex;
            public int Publish;
            public int ExamDay;
            public int PrepDays;
        }

        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine()).Split(' ');
            int N_Days = int.Parse(s[0]);
            int Total_exams = int.Parse(s[1]);
            List<Exam> list2 = new List<Exam>();
            for (int i = 0; i < Total_exams; ++i)
            {
                Exam exm;
                s = (Console.ReadLine()).Split(' ');
                exm.ExamIndex = i + 1;
                exm.Publish = int.Parse(s[0]);
                exm.ExamDay = int.Parse(s[1]);
                exm.PrepDays = int.Parse(s[2]);
                list2.Add(exm);
            }
           list2.Sort((x, y) => x.ExamDay.CompareTo(y.ExamDay));
            List<int> seq = new List<int>();
            for (int i = 0; i <= N_Days; ++i)
            {
                seq.Add(0);
            }
            int print = 0;
            foreach (Exam l in list2)
            {
                if (l.Publish - 1 + l.PrepDays < l.ExamDay)
                {
                    if (Ispossible(l.ExamIndex, l, seq))
                    {
                        seq[l.ExamDay] = Total_exams + 1;

                        continue;
                    }
                    else
                    {
                        print = -1;
                        break;
                    }
                }
            }
            if (print == 0)
            {
                if (seq.Sum() != 0)
                {
                    for (int j = 1; j < seq.Count; ++j)
                    {
                        if (j + 1 == seq.Count)
                        {
                            Console.Write(seq[j]);
                            continue;
                        }
                        Console.Write(seq[j] + " ");
                    }
                }
                else
                {
                    Console.WriteLine("-1");
                }
            }
            else
            {
                Console.WriteLine("-1");
            }

           // Console.ReadKey();
        }

        private static bool Ispossible(int exam_number, Exam l, List<int> seq)
        {
            int days = l.PrepDays;

            int i = l.Publish;
            while (i < l.ExamDay && days > 0)
            {
                if (seq[i] == 0)
                {
                    seq[i] = exam_number;
                    days--;
                }
                i++;
            }
            return days == 0 ? true : false;
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petya_Exam
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine()).Split(' ');
            int N_Days = int.Parse(s[0]);
            int Total_exams = int.Parse(s[1]);
            List<List<int>> list = new List<List<int>>();
            for(int i=0; i<Total_exams; ++i)
            {
                s = (Console.ReadLine()).Split(' ');
                List<int> ls = new List<int>();
                ls.Add(int.Parse(s[0]));
                ls.Add(int.Parse(s[1]));
                ls.Add(int.Parse(s[2]));
                list.Add(ls);
            }
            List<int> seq = new List<int>();
            for(int i=0; i<=N_Days;++i)
            {
                seq.Add(0);
            }
            int print =0;
            int exam_number = 1;
            foreach(List<int> l in list)
            {
                //int n = l[0];
                if(l[0]-1+l[2]<l[1])
                {
                    if(Ispossible(exam_number,l,seq))
                    {
                        seq[l[1]] = Total_exams + 1;
                        exam_number++;
                        continue;
                    }
                    else
                    {
                        print = -1;
                        break;
                    }
                }
            }
            if(print==0)
            {
                for (int j = 1; j < seq.Count; ++j)
                {
                    if(j+1==seq.Count)
                    {
                        Console.Write(seq[j]);
                        continue;
                    }
                    Console.Write(seq[j] + " ");
                }

            }
            else
            {
                Console.WriteLine(print);
            }
            Console.WriteLine();
            //Console.ReadKey();
        }

        private static bool Ispossible(int exam_number, List<int> l, List<int> seq)
        {
            int days = l[2];
            // for(int i=l[0]; i<l[1]; ++i)
            int i = l[0];
            while(i<l[1]&& days>0)
            {
                if(seq[i]==0)
                {
                    seq[i] = exam_number;
                    days--;
                }
                i++;
            }
            return days==0?true:false;
        }
    }
}